Created
March 30, 2020 08:15
-
-
Save Alpha255/1aeba4928267c4660ac49e9e312b60d9 to your computer and use it in GitHub Desktop.
Steal from https://github.com/liuyunbin/liuyunbin-toys/blob/master/cpp/type_traits/is_enum/main.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <type_traits> | |
| template <typename T> | |
| std::true_type test_is_class_or_union(int T::*); | |
| template <typename T> | |
| std::false_type test_is_class_or_union(...); | |
| template <typename T> | |
| struct is_class_or_union : decltype(test_is_class_or_union<T>(nullptr)) {}; | |
| template <typename T> | |
| struct is_enum : public std::integral_constant<bool, | |
| !std::is_void<T>::value && | |
| !std::is_null_pointer<T>::value && | |
| !std::is_integral<T>::value && | |
| !std::is_floating_point<T>::value && | |
| !std::is_array<T>::value && | |
| !std::is_function<T>::value && | |
| !std::is_pointer<T>::value && | |
| !std::is_reference<T>::value && | |
| !std::is_member_pointer<T>::value && | |
| !::is_class_or_union<T>::value> | |
| {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment