39 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 40 #error "Only <final/final.h> can be included directly." 46 #include <type_traits> 49 #include "final/util/fstring.h" 64 using cleanCondition_t = \
65 std::conditional_t<std::is_array<T>::value
66 , std::remove_extent_t<T>*
67 , std::conditional_t<std::is_function<T>::value
68 , std::add_pointer_t<T>
95 using remove_ref = std::remove_reference_t<T>;
99 using type = internal::cleanCondition_t<remove_ref>;
102 static_assert ( ! std::is_void<remove_ref>::value
103 ,
"FData cannot store void types" );
104 static_assert ( ! internal::is_reference_wrapper_v<remove_ref>
105 ,
"FData cannot store reference_wrapper types directly" );
109 template <
typename T>
110 using clean_fdata_t =
typename cleanFData<T>::type;
113 template <
typename T>
114 inline auto makeFData (T&& data) -> std::unique_ptr<FData<clean_fdata_t<T>>>
116 using CleanT = clean_fdata_t<T>;
117 static_assert ( std::is_constructible<CleanT, T&&>::value
118 ,
"Cannot construct FData with the provided type" );
120 return std::make_unique<FData<clean_fdata_t<T>>>(std::forward<T>(data));
138 virtual auto getClassName()
const ->
FString 140 return "FDataAccess";
144 constexpr
auto get() noexcept -> clean_fdata_t<T>&
146 static_assert ( ! std::is_void<T>::value
147 ,
"Cannot get void type from FDataAccess" );
153 constexpr
auto get()
const noexcept ->
const clean_fdata_t<T>&
155 static_assert ( ! std::is_void<T>::value
156 ,
"Cannot get void type from FDataAccess" );
164 constexpr
void set (V&& data) noexcept(noexcept(std::declval<
FData<T>>().
set(std::forward<V>(data))))
166 static_assert ( std::is_convertible<V&&, T>::value
167 ,
"Type V must be convertible to type T" );
169 static_cast<FData<T>*
>(
this)->
set(std::forward<V>(data));
178 template <
typename T>
183 using value_type = T;
184 using reference = value_type&;
185 using const_reference =
const value_type&;
186 using T_nocv = std::remove_cv_t<value_type>;
189 static constexpr
bool nothrow_copy_ctor_v = \
190 std::is_nothrow_copy_constructible<value_type>::value;
192 static constexpr
bool nothrow_move_ctor_v = \
193 std::is_nothrow_move_constructible<value_type>::value;
195 static constexpr
bool nothrow_copy_asgn_v = \
196 std::is_nothrow_copy_assignable<value_type>::value;
198 static constexpr
bool nothrow_move_asgn_v = \
199 std::is_nothrow_move_assignable<value_type>::value;
202 static_assert ( ! std::is_void<value_type>::value
203 ,
"FData cannot store void types") ;
204 static_assert ( ! std::is_reference<value_type>::value
205 ,
"FData cannot store reference types directly" );
208 explicit FData (value_type& v) noexcept
212 explicit FData (value_type&& v) noexcept(nothrow_move_ctor_v)
213 : value{std::move(v)}
217 ~
FData() noexcept
override =
default;
219 FData (
const FData& d) noexcept(nothrow_copy_ctor_v)
222 , value_ref{d.isInitializedCopy() ? std::ref(value) : d.value_ref}
227 , value{std::move(d.value)}
228 , value_ref{d.isInitializedCopy() ? std::ref(value) : d.value_ref}
232 auto operator = (
const FData& d) noexcept(nothrow_copy_asgn_v) ->
FData&
238 if ( d.isInitializedCopy() )
241 value_ref = d.value_ref;
248 auto operator = (
FData&& d) noexcept ->
FData&
252 value = std::move(d.value);
254 if ( d.isInitializedCopy() )
257 value_ref = std::move(d.value_ref);
264 constexpr
auto operator () ()
const noexcept(nothrow_copy_ctor_v) -> value_type
269 constexpr
explicit operator value_type ()
const noexcept(nothrow_copy_ctor_v)
274 constexpr
auto operator << (const_reference v) noexcept(nothrow_copy_asgn_v) ->
FData&
281 auto getClassName()
const ->
FString override 286 constexpr
auto get()
const noexcept -> const_reference
288 return value_ref.get();
291 constexpr
auto get() noexcept -> reference
293 return value_ref.get();
297 constexpr
void set (
const value_type& v) noexcept(nothrow_copy_asgn_v)
302 constexpr
void set (value_type&& v) noexcept(nothrow_move_asgn_v)
304 value_ref.get() = std::move(v);
308 constexpr
auto isInitializedCopy()
const noexcept ->
bool 310 return std::addressof(value) == std::addressof(value_ref.get());
313 constexpr
auto isInitializedReference()
const noexcept ->
bool 315 return ! isInitializedCopy();
319 constexpr
friend auto operator << (std::ostream &os,
const FData& data) -> std::ostream&
321 os << data.value_ref.get();
328 std::reference_wrapper<value_type> value_ref;
Definition: fstring.h:906
Definition: class_template.cpp:25