12 #ifndef SST_CORE_SERIALIZATION_IMPL_SERIALIZE_UTILITY_H 13 #define SST_CORE_SERIALIZATION_IMPL_SERIALIZE_UTILITY_H 15 #ifndef SST_INCLUDING_SERIALIZE_H 17 "The header file sst/core/serialization/impl/serialize_utility.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serialize.h" 25 #include <type_traits> 33 template <
template <
class...>
class,
template <
class...>
class>
34 constexpr
bool is_same_template_v =
false;
36 template <
template <
class...>
class T>
37 constexpr
bool is_same_template_v<T, T> =
true;
39 template <
template <
class...>
class T1,
template <
class...>
class T2>
40 using is_same_template = std::bool_constant<is_same_template_v<T1, T2>>;
45 template <
class,
template <
class...>
class>
46 constexpr
bool is_same_type_template_v =
false;
48 template <
template <
class...>
class T1,
class... T1ARGS,
template <
class...>
class T2>
49 constexpr
bool is_same_type_template_v<T1<T1ARGS...>, T2> = is_same_template_v<T1, T2>;
51 template <
class T,
template <
class...>
class TT>
52 using is_same_type_template = std::bool_constant<is_same_type_template_v<T, TT>>;
57 #if __cplusplus < 202002l 60 constexpr
bool is_unbounded_array_v =
false;
63 constexpr
bool is_unbounded_array_v<T[]> =
true;
66 using is_unbounded_array = std::bool_constant<is_unbounded_array_v<T>>;
70 using std::is_unbounded_array;
71 using std::is_unbounded_array_v;
79 template <
class,
class =
void>
96 constexpr
bool has_serialize_order_v = has_serialize_order<T>::value;
101 namespace pvt_nfields {
113 template <
class C,
class,
bool = std::is_aggregate_v<C>,
class = C>
114 constexpr
bool nfields_ge_impl =
false;
118 template <
class C,
size_t... I>
119 constexpr
bool nfields_ge_impl<C, std::index_sequence<I...>,
true, decltype(C { (I,
glob())... })> =
true;
122 template <
class C,
size_t N>
123 constexpr
bool nfields_ge = nfields_ge_impl<C, std::make_index_sequence<N>>;
126 template <
class C,
size_t L,
size_t H,
size_t M = L + (H - L) / 2,
bool = M != L>
127 constexpr
size_t b_search = L;
130 template <
class C,
size_t L,
size_t H,
size_t M,
bool>
131 constexpr
size_t b_search_next = b_search<C, L, M>;
134 template <
class C,
size_t L,
size_t H,
size_t M>
135 constexpr
size_t b_search_next<C, L, H, M, true> = b_search<C, M, H>;
138 template <
class C,
size_t L,
size_t H,
size_t M>
139 constexpr
size_t b_search<C, L, H, M, true> = b_search_next<C, L, H, M, nfields_ge<C, M>>;
142 template <
class C,
size_t N = 1,
bool = true>
143 constexpr
size_t nfields = nfields<C, N * 2, nfields_ge<C, N * 2>>;
146 template <
class C,
size_t N>
147 constexpr
size_t nfields<C, N, false> = b_search<C, 0, N>;
153 constexpr
size_t nfields = pvt_nfields::nfields<C>;
189 namespace pvt_trivial {
194 template <
class C,
bool = std::conjunction_v<std::is_aggregate<C>, std::is_trivially_copyable<C>,
195 std::is_standard_layout<C>, std::negation<has_serialize_order<C>>>>
196 constexpr
bool is_trivially_serializable_v =
197 std::disjunction_v<std::is_arithmetic<C>, std::is_enum<C>, std::is_member_object_pointer<C>>;
203 template <
class C,
class = std::enable_if_t<is_trivially_serializable_v<C>>>
208 template <
class C,
class,
class = C>
209 constexpr
bool has_ts_fields =
false;
213 template <
class C,
size_t... I>
214 constexpr
bool has_ts_fields<C, std::index_sequence<I...>, decltype(C { (I,
glob_ts())... })> =
true;
218 constexpr
bool is_trivially_serializable_v<C, true> = has_ts_fields<C, std::make_index_sequence<nfields<C>>>;
222 constexpr
bool is_trivially_serializable_v<std::bitset<N>,
false> =
true;
226 constexpr
bool is_trivially_serializable_v<std::complex<C>,
false> =
true;
228 #ifndef __STDC_NO_COMPLEX__ 230 inline constexpr
bool is_trivially_serializable_v<float _Complex, false> =
true;
233 inline constexpr
bool is_trivially_serializable_v<double _Complex, false> =
true;
236 inline constexpr
bool is_trivially_serializable_v<long double _Complex, false> =
true;
242 inline constexpr
bool is_trivially_serializable_v<_Float16, false> =
true;
246 #ifdef __SIZEOF_INT128__ 248 inline constexpr
bool is_trivially_serializable_v<__int128, false> =
true;
251 inline constexpr
bool is_trivially_serializable_v<unsigned __int128, false> =
true;
258 constexpr
bool is_trivially_serializable_v = pvt_trivial::is_trivially_serializable_v<C>;
261 using is_trivially_serializable = std::bool_constant<is_trivially_serializable_v<C>>;
265 #endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_UTILITY_H Definition: serialize_utility.h:80
Definition: serialize_utility.h:105
Definition: serialize_utility.h:200