in include/ylt/struct_pack/type_id.hpp [287:366]
constexpr type_id get_type_id() {
static_assert(CHAR_BIT == 8);
// compatible member, which should be ignored in MD5 calculated.
if constexpr (user_defined_serialization<T>) {
return type_id::user_defined_type;
}
else if constexpr (ylt::reflection::optional<T> && is_compatible_v<T>) {
return type_id::compatible_t;
}
else if constexpr (detail::varint_t<T, parent_tag>) {
return get_varint_type<T, parent_tag>();
}
else if constexpr (std::is_enum_v<T>) {
return get_integral_type<std::underlying_type_t<T>>();
}
else if constexpr (std::is_integral_v<T>
#if (__GNUC__ || __clang__) && defined(STRUCT_PACK_ENABLE_INT128)
|| std::is_same_v<__int128, T> ||
std::is_same_v<unsigned __int128, T>
#endif
) {
return get_integral_type<T>();
}
else if constexpr (std::is_floating_point_v<T>) {
return get_floating_point_type<T>();
}
else if constexpr (std::is_same_v<T, std::monostate> ||
std::is_same_v<T, void> || std::is_abstract_v<T>) {
return type_id::monostate_t;
}
#ifdef STRUCT_PACK_ENABLE_UNPORTABLE_TYPE
else if constexpr (bitset<T>) {
return type_id::bitset_t;
}
#endif
else if constexpr (string<T>) {
return type_id::string_t;
}
else if constexpr (array<T> || c_array<T> || static_span<T>) {
return type_id::array_t;
}
else if constexpr (map_container<T>) {
return type_id::map_container_t;
}
else if constexpr (set_container<T>) {
return type_id::set_container_t;
}
else if constexpr (container<T>) {
return type_id::container_t;
}
else if constexpr (ylt::reflection::optional<T>) {
return type_id::optional_t;
}
else if constexpr (unique_ptr<T>) {
if constexpr (is_base_class<typename T::element_type>) {
return type_id::polymorphic_unique_ptr_t;
}
else {
return type_id::optional_t;
}
}
else if constexpr (is_variant_v<T>) {
static_assert(
std::variant_size_v<T> > 1 ||
(std::variant_size_v<T> == 1 &&
!std::is_same_v<std::variant_alternative_t<0, T>, std::monostate>),
"The variant should contain's at least one type!");
static_assert(std::variant_size_v<T> < 256, "The variant is too complex!");
return type_id::variant_t;
}
else if constexpr (ylt::reflection::expected<T>) {
return type_id::expected_t;
}
else if constexpr (is_trivial_tuple<T> || pair<T> || std::is_class_v<T>) {
return type_id::struct_t;
}
else {
static_assert(!sizeof(T), "not supported type");
}
}