| 1 |
// -*-c++-*- |
| 2 |
// vim: set ft=cpp: |
| 3 |
|
| 4 |
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
| 5 |
file LICENSE.rst or https://cmake.org/licensing for details. */ |
| 6 |
#pragma once |
| 7 |
|
| 8 |
#include <type_traits> // IWYU pragma: export |
| 9 |
|
| 10 |
namespace cm { |
| 11 |
|
| 12 |
#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) |
| 13 |
|
| 14 |
template <bool B, typename T = void> |
| 15 |
using enable_if_t = std::enable_if_t<B, T>; |
| 16 |
|
| 17 |
using std::conditional_t; |
| 18 |
using std::decay_t; |
| 19 |
using std::remove_cv_t; |
| 20 |
using std::remove_reference_t; |
| 21 |
|
| 22 |
#else |
| 23 |
|
| 24 |
template <bool B, typename T = void> |
| 25 |
using enable_if_t = typename std::enable_if<B, T>::type; |
| 26 |
|
| 27 |
template <bool B, typename T, typename F> |
| 28 |
using conditional_t = typename std::conditional<B, T, F>::type; |
| 29 |
|
| 30 |
template <typename T> |
| 31 |
using decay_t = typename std::decay<T>::type; |
| 32 |
|
| 33 |
template <typename T> |
| 34 |
using remove_cv_t = typename std::remove_cv<T>::type; |
| 35 |
|
| 36 |
template <typename T> |
| 37 |
using remove_reference_t = typename std::remove_reference<T>::type; |
| 38 |
|
| 39 |
#endif // C++14 (_t aliases) |
| 40 |
|
| 41 |
#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) |
| 42 |
|
| 43 |
using std::bool_constant; |
| 44 |
|
| 45 |
using std::invoke_result; |
| 46 |
using std::invoke_result_t; |
| 47 |
using std::void_t; |
| 48 |
|
| 49 |
#else |
| 50 |
|
| 51 |
// Helper classes |
| 52 |
template <bool B> |
| 53 |
using bool_constant = std::integral_constant<bool, B>; |
| 54 |
|
| 55 |
// Miscellaneous transformations |
| 56 |
template <typename F, typename... ArgTypes> |
| 57 |
using invoke_result = std::result_of<F(ArgTypes...)>; |
| 58 |
|
| 59 |
template <typename F, typename... ArgTypes> |
| 60 |
using invoke_result_t = typename invoke_result<F, ArgTypes...>::type; |
| 61 |
|
| 62 |
template <typename... ArgTypes> |
| 63 |
struct make_void |
| 64 |
{ |
| 65 |
typedef void type; |
| 66 |
}; |
| 67 |
template <typename... ArgTypes> |
| 68 |
using void_t = typename make_void<ArgTypes...>::type; |
| 69 |
|
| 70 |
#endif |
| 71 |
|
| 72 |
#if (__cplusplus >= 202302L || \ |
| 73 |
(defined(_MSVC_LANG) && _MSVC_LANG >= 202302L)) && \ |
| 74 |
__cpp_lib_is_scoped_enum == 202011L |
| 75 |
|
| 76 |
using std::is_scoped_enum; |
| 77 |
|
| 78 |
#else |
| 79 |
|
| 80 |
namespace internals { |
| 81 |
template <typename T, bool = std::is_enum<T>::value> |
| 82 |
struct is_scoped_enum_helper : std::false_type |
| 83 |
{ |
| 84 |
}; |
| 85 |
|
| 86 |
template <typename T> |
| 87 |
struct is_scoped_enum_helper<T, true> |
| 88 |
: public cm::bool_constant< |
| 89 |
!std::is_convertible<T, typename std::underlying_type<T>::type>::value> |
| 90 |
{ |
| 91 |
}; |
| 92 |
} // namespace internals |
| 93 |
|
| 94 |
template <typename T> |
| 95 |
struct is_scoped_enum : public internals::is_scoped_enum_helper<T> |
| 96 |
{ |
| 97 |
}; |
| 98 |
|
| 99 |
#endif // is_scoped_enum |
| 100 |
|
| 101 |
} // namespace cm |