ADTF
Loading...
Searching...
No Matches
type_traits.h
Go to the documentation of this file.
1
14
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))
28namespace std {
34template <typename...>
35using 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
40namespace std {
44template <typename T>
45constexpr bool is_enum_v = is_enum<T>::value;
46} // namespace std
47#endif // !HAS_IS_ENUM_V
48
49namespace a_util {
54
61template <typename T, bool = std::is_enum_v<T>>
66 using type = T;
67};
68
74template <typename T>
79 using type = std::underlying_type_t<T>;
80};
81
88template <class T, bool is_enum = std::is_enum_v<T>>
90
92namespace 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))
100template <class T, class U, class = void>
101struct is_explicitly_convertible_to_impl : std::false_type {
102};
103
104template <class T, class U>
105struct 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
124template <class T, class U>
125struct is_explicitly_convertible_to : detail::is_explicitly_convertible_to_impl<T, U> {
126};
127
138template <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
Definition type_traits.h:139
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
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
Definition type_traits.h:45