ADTF  3.18.2
type_traits.h
Go to the documentation of this file.
1 
15 #ifndef A_UTIL_UTIL_BASE_TYPE_TRAITS_H
16 #define A_UTIL_UTIL_BASE_TYPE_TRAITS_H
17 
19 
20 #include <type_traits>
21 
22 #if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
23 #pragma GCC diagnostic ignored \
24  "-Wattributes" // standard type attributes are ignored when used in templates
25 #endif
26 
27 #if (defined(__GNUC__) && (__GNUC__ < 7)) || (defined(_MSC_VER) && (_MSC_VER < 1920))
28 namespace std {
34 template <typename...>
35 using void_t = void;
36 } // namespace std
37 #endif // (defined(__GNUC__) && (__GNUC__ < 7)) || (defined(_MSC_VER) && (_MSC_VER < 1920))
38 
39 #if !HAS_IS_ENUM_V
40 namespace std {
44 template <typename T>
45 constexpr bool is_enum_v = is_enum<T>::value;
46 } // namespace std
47 #endif // !HAS_IS_ENUM_V
48 
49 namespace a_util {
61 template <typename T, bool = std::is_enum_v<T>>
66  using type = T;
67 };
68 
74 template <typename T>
79  using type = std::underlying_type_t<T>;
80 };
81 
88 template <class T, bool is_enum = std::is_enum_v<T>>
90 
92 namespace detail {
93 
94 // 'is_explicitly_convertible_to_impl' implementations are copied from:
95 // @author [Hunter Kohler](https://stackoverflow.com/users/8419650/hunter-kohler) here:
96 // https://stackoverflow.com/a/71563534
97 // @copyright [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)
98 // (See: [What is the license for the content I post?]
99 // (https://stackoverflow.com/help/licensing))
100 template <class T, class U, class = void>
101 struct is_explicitly_convertible_to_impl : std::false_type {
102 };
103 
104 template <class T, class U>
105 struct is_explicitly_convertible_to_impl<T,
106  U,
107  std::void_t<decltype(static_cast<U>(std::declval<T>()))>>
108  : std::true_type {
109 };
110 
111 } // namespace detail
113 
124 template <class T, class U>
125 struct is_explicitly_convertible_to : detail::is_explicitly_convertible_to_impl<T, U> {
126 };
127 
138 template <class T, class U>
140 
142 } // namespace a_util
143 
144 #if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
145 #pragma GCC diagnostic warning \
146  "-Wattributes" // standard type attributes are ignored when used in templates
147 #endif
148 
149 #endif /* A_UTIL_UTIL_BASE_TYPE_TRAITS_H */
typename underlying_type_or_type< T, is_enum >::type underlying_type_or_type_t
Retrieves the underlying type if T is an enum, otherwise the type itself.
Definition: type_traits.h:89
constexpr bool is_explicitly_convertible_to_v
Helper variable template for is_explicitly_convertible_to.
Definition: type_traits.h:139
Checks for std::is_enum_v and defines HAS_IS_ENUM_V accordingly.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:24
Checks if there is an explicitly defined conversion from U to T.
Definition: type_traits.h:125
Retrieves the underlying type of the enum type T.
Definition: type_traits.h:75
std::underlying_type_t< T > type
The type of the underlying type retrieved.
Definition: type_traits.h:79
Retrieves the underlying type if T is an enum, otherwise the type itself.
Definition: type_traits.h:62
T type
The type of the underlying type retrieved.
Definition: type_traits.h:66
constexpr bool is_enum_v
C++17 backport of std::is_enum_v.
Definition: type_traits.h:45