Added is_enum

This commit is contained in:
John Wellbelove 2022-07-14 18:00:14 +01:00
parent 274a52db52
commit 4903e0cac8
3 changed files with 31 additions and 20 deletions

View File

@ -716,26 +716,31 @@ namespace etl
///\ingroup type_traits
/// Implemented by checking if type is convertable to an integer thru static_cast
namespace private_type_traits {
namespace private_type_traits
{
// Base case
template <typename T, typename = int>
struct is_convertible_to_int : false_type {};
struct is_convertible_to_int : false_type
{
};
// Selected if `static_cast<int>(declval<T>())` is a valid statement
// 2nd template argument of base case defaults to int to ensure that this partial specialization is always tried first
template <typename T>
struct is_convertible_to_int<
T, decltype(static_cast<int>(declval<T>()))>
: true_type {};
struct is_convertible_to_int<T, decltype(static_cast<int>(declval<T>()))>
: true_type
{
};
}
} // namespace private_type_traits
template <typename T>
struct is_enum
: integral_constant<bool, private_type_traits::is_convertible_to_int<T>::value &&
!is_class<T>::value &&
!is_arithmetic<T>::value &&
!is_reference<T>::value> {};
!is_class<T>::value &&
!is_arithmetic<T>::value &&
!is_reference<T>::value>
{
};
#if ETL_USING_CPP17
template <typename T>

View File

@ -704,26 +704,31 @@ namespace etl
///\ingroup type_traits
/// Implemented by checking if type is convertable to an integer thru static_cast
namespace private_type_traits {
namespace private_type_traits
{
// Base case
template <typename T, typename = int>
struct is_convertible_to_int : false_type {};
struct is_convertible_to_int : false_type
{
};
// Selected if `static_cast<int>(declval<T>())` is a valid statement
// 2nd template argument of base case defaults to int to ensure that this partial specialization is always tried first
template <typename T>
struct is_convertible_to_int<
T, decltype(static_cast<int>(declval<T>()))>
: true_type {};
struct is_convertible_to_int<T, decltype(static_cast<int>(declval<T>()))>
: true_type
{
};
}
} // namespace private_type_traits
template <typename T>
struct is_enum
: integral_constant<bool, private_type_traits::is_convertible_to_int<T>::value &&
!is_class<T>::value &&
!is_arithmetic<T>::value &&
!is_reference<T>::value> {};
!is_class<T>::value &&
!is_arithmetic<T>::value &&
!is_reference<T>::value>
{
};
#if ETL_USING_CPP17
template <typename T>

View File

@ -2,6 +2,7 @@
20.31.0
Added etl::poly_span
Refacted parts of etl::span, including prevent compound statements in constexpr methods for C++11
Added etl::is_enum
===============================================================================
20.30.1