[ox/std] Add is_union_v and is_class_v

This commit is contained in:
Gary Talent 2019-07-15 18:15:14 -05:00
parent 0b218f57c2
commit 02d92449f9

View File

@ -68,11 +68,14 @@ template<> struct is_integral<uint64_t>: ox::true_type {};
template<typename T> struct is_union: ox::integral_constant<bool, std::is_union_v<T>> {};
template<typename T>
constexpr bool is_union_v = ox::is_union<T>();
// indicates the type can have members, but not that it necessarily does
template<typename T>
constexpr uint8_t memberable(int T::*) { return true; }
constexpr bool memberable(int T::*) { return true; }
template<typename T>
constexpr uint16_t memberable(...) { return false; }
constexpr bool memberable(...) { return false; }
template<typename T>
struct is_class: ox::integral_constant<bool, !ox::is_union<T>::value && ox::memberable<T>(0)> {};
@ -85,6 +88,9 @@ static_assert(ox::is_class<TestUnion>::value == false);
static_assert(ox::is_class<int>::value == false);
}
template<typename T>
constexpr bool is_class_v = ox::is_class<T>();
template<typename T>
constexpr bool is_signed = ox::integral_constant<bool, T(-1) < T(0)>::value;