Update type_traits_generator.h

This commit is contained in:
Filipe Cuim 2025-10-22 11:36:57 +01:00
parent 5a62dc39ea
commit 94822732a2
No known key found for this signature in database
3 changed files with 202 additions and 182 deletions

View File

@ -742,11 +742,11 @@ namespace etl
///\ingroup type_traits
/// Implemented by checking if type is convertible to an integer through static_cast
namespace private_type_traits
namespace private_type_traits
{
// Base case
template <typename T, typename = int>
struct is_convertible_to_int
struct is_convertible_to_int
: false_type
{
};
@ -755,7 +755,7 @@ namespace etl
// 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
: true_type
{
};
}
@ -765,7 +765,7 @@ namespace etl
: 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_reference<T>::value>
{
};
@ -1577,7 +1577,7 @@ typedef integral_constant<bool, true> true_type;
//***************************************************************************
/// Get the Nth base of a recursively inherited type.
/// Requires that the class has defined 'base_type'.
//***************************************************************************
//***************************************************************************
// Recursive definition of the type.
template <size_t Index, typename TType>
struct nth_base
@ -1837,142 +1837,7 @@ typedef integral_constant<bool, true> true_type;
using is_trivially_copyable = etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>;
#endif
#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS)
//*********************************************
// Use the compiler's builtins.
//*********************************************
//*********************************************
// is_assignable
template<typename T1, typename T2>
struct is_assignable
{
static ETL_CONSTANT bool value = __is_assignable(T1, T2);
};
#if ETL_USING_CPP11
//*********************************************
// is_constructible
template<typename T, typename... TArgs>
struct is_constructible
{
static ETL_CONSTANT bool value = __is_constructible(T, TArgs...);
};
#else
//*********************************************
// is_constructible
template<typename T, typename TArgs = void>
struct is_constructible
{
static ETL_CONSTANT bool value = __is_constructible(T, TArgs);
};
//*********************************************
// is_constructible
template<typename T>
struct is_constructible<T, void>
{
static ETL_CONSTANT bool value = __is_constructible(T);
};
#endif
//*********************************************
// is_copy_constructible
template <typename T>
struct is_copy_constructible : public etl::is_constructible<T, typename etl::add_lvalue_reference<const T>::type>
{
};
//*********************************************
// is_move_constructible
template <typename T>
struct is_move_constructible : public etl::is_constructible<T, T>
{
};
#if ETL_USING_CPP11
//*********************************************
// is_trivially_constructible
template <typename T, typename... TArgs>
struct is_trivially_constructible
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs...);
#endif
};
#else
//*********************************************
// is_trivially_constructible
template <typename T, typename TArgs = void>
struct is_trivially_constructible
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs);
#endif
};
//*********************************************
// is_trivially_constructible
template <typename T>
struct is_trivially_constructible<T, void>
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_constructible(T);
#endif
};
#endif
//*********************************************
// is_trivially_copy_constructible
template <typename T>
struct is_trivially_copy_constructible : public is_trivially_constructible<T, typename add_lvalue_reference<const T>::type>
{
};
//*********************************************
// is_trivially_destructible
template <typename T>
struct is_trivially_destructible
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_destructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_destructible(T);
#endif
};
//*********************************************
// is_trivially_copy_assignable
template <typename T>
struct is_trivially_copy_assignable
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_copy(T);
#else
static ETL_CONSTANT bool value = __is_trivially_copyable(T);
#endif
};
//*********************************************
// is_trivially_copyable
template <typename T>
struct is_trivially_copyable
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_copy(T);
#else
static ETL_CONSTANT bool value = __is_trivially_copyable(T);
#endif
};
#elif defined(ETL_USER_DEFINED_TYPE_TRAITS) && !defined(ETL_USE_TYPE_TRAITS_BUILTINS)
#elif defined(ETL_USER_DEFINED_TYPE_TRAITS)
//*********************************************
// Force the user to provide specialisations for
@ -2108,21 +1973,38 @@ typedef integral_constant<bool, true> true_type;
#else
//*********************************************
// Assume that anything other than arithmetics
// and pointers return false for the traits.
// Deduce traits based on if builtins exist.
//*********************************************
//*********************************************
// is_assignable
#if ETL_USING_BUILTIN_IS_ASSIGNABLE
template<typename T1, typename T2>
struct is_assignable
{
static ETL_CONSTANT bool value = __is_assignable(T1, T2);
};
#else
template <typename T1, typename T2>
struct is_assignable : public etl::bool_constant<(etl::is_arithmetic<T1>::value || etl::is_pointer<T1>::value) && (etl::is_arithmetic<T2>::value || etl::is_pointer<T2>::value)>
{
};
#endif
#if ETL_USING_CPP11
#if ETL_USING_BUILTIN_IS_CONSTRUCTIBLE
//*********************************************
// is_constructible
template<typename T, typename... TArgs>
struct is_constructible
{
static ETL_CONSTANT bool value = __is_constructible(T, TArgs...);
};
#else
//***************************************************************************
/// is_constructible
namespace private_type_traits
/// is_constructible_
namespace private_type_traits
{
template <class, class T, class... Args>
struct is_constructible_ : etl::false_type {};
@ -2135,6 +2017,7 @@ typedef integral_constant<bool, true> true_type;
// is_constructible
template <class T, class... Args>
using is_constructible = private_type_traits::is_constructible_<void_t<>, T, Args...>;
#endif
//*********************************************
// is_copy_constructible
@ -2153,7 +2036,31 @@ typedef integral_constant<bool, true> true_type;
template <> struct is_move_constructible<void const volatile> : public false_type{};
#else
#if ETL_USING_BUILTIN_IS_CONSTRUCTIBLE
//*********************************************
// is_constructible
template<typename T, typename TArgs = void>
struct is_constructible
{
static ETL_CONSTANT bool value = __is_constructible(T, TArgs);
};
//*********************************************
// is_constructible
template<typename T>
struct is_constructible<T, void>
{
static ETL_CONSTANT bool value = __is_constructible(T);
};
//*********************************************
// is_copy_constructible
template <class T> struct is_copy_constructible : public is_constructible<T, typename etl::add_lvalue_reference<typename etl::add_const<T>::type>::type>{};
//*********************************************
// is_move_constructible
template <typename T> struct is_move_constructible : public is_constructible<T, T>{};
#else
//*********************************************
// is_copy_constructible
template <typename T>
@ -2168,7 +2075,53 @@ typedef integral_constant<bool, true> true_type;
{
};
#endif
#endif
#if ETL_USING_BUILTIN_IS_TRIVIALLY_CONSTRUCTIBLE
#if ETL_USING_CPP11
//*********************************************
// is_trivially_constructible
template <typename T, typename... TArgs>
struct is_trivially_constructible
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs...);
#endif
};
#else
//*********************************************
// is_trivially_constructible
template <typename T, typename TArgs = void>
struct is_trivially_constructible
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs);
#endif
};
//*********************************************
// is_trivially_constructible
template <typename T>
struct is_trivially_constructible<T, void>
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_constructible(T);
#endif
};
#endif
//*********************************************
// is_trivially_copy_constructible
template <typename T>
struct is_trivially_copy_constructible : public is_trivially_constructible<T, typename add_lvalue_reference<const T>::type>
{
};
#else
//*********************************************
// is_trivially_constructible
template <typename T>
@ -2182,28 +2135,70 @@ typedef integral_constant<bool, true> true_type;
struct is_trivially_copy_constructible : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};
#endif
#if ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE
//*********************************************
// is_trivially_destructible
template <typename T>
struct is_trivially_destructible
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_destructor(T);
#else
static ETL_CONSTANT bool value = __is_trivially_destructible(T);
#endif
};
#else
//*********************************************
// is_trivially_destructible
template <typename T>
struct is_trivially_destructible : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};
#endif
#if ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE
//*********************************************
// is_trivially_copy_assignable
template <typename T>
struct is_trivially_copy_assignable
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_assign(T);
#else
static ETL_CONSTANT bool value = __is_trivially_assignable(typename add_lvalue_reference<T>::type,
typename add_lvalue_reference<const T>::type);
#endif
};
#else
//*********************************************
// is_trivially_copy_assignable
template <typename T>
struct is_trivially_copy_assignable : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};
#endif
#if ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE
//*********************************************
// is_trivially_copyable
template <typename T>
struct is_trivially_copyable
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_copy(T);
#else
static ETL_CONSTANT bool value = __is_trivially_copyable(T);
#endif
};
#else
//*********************************************
// is_trivially_copyable
template <typename T>
struct is_trivially_copyable : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};
#endif
template <typename T1, typename T2>
@ -2238,8 +2233,8 @@ typedef integral_constant<bool, true> true_type;
template<typename T, typename... TArgs>
inline constexpr bool is_constructible_v = etl::is_constructible<T, TArgs...>::value;
template<typename T, typename... TArgs>
inline constexpr bool is_default_constructible_v = etl::is_default_constructible<T, TArgs...>::value;
template<typename T>
inline constexpr bool is_default_constructible_v = etl::is_default_constructible<T>::value;
template<typename T>
inline constexpr bool is_copy_constructible_v = etl::is_copy_constructible<T>::value;
@ -2247,8 +2242,8 @@ typedef integral_constant<bool, true> true_type;
template<typename T>
inline constexpr bool is_move_constructible_v = etl::is_move_constructible<T>::value;
template <typename T>
inline constexpr bool is_trivially_constructible_v = etl::is_trivially_constructible<T>::value;
template <typename T, typename... TArgs>
inline constexpr bool is_trivially_constructible_v = etl::is_trivially_constructible<T, TArgs...>::value;
template <typename T>
inline constexpr bool is_trivially_copy_constructible_v = etl::is_trivially_copy_constructible<T>::value;
@ -2263,6 +2258,7 @@ typedef integral_constant<bool, true> true_type;
inline constexpr bool is_trivially_copyable_v = etl::is_trivially_copyable<T>::value;
#endif
#endif // ETL_USING_STL && ETL_USING_CPP11 && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS)
#if ETL_USING_CPP11
//*********************************************
@ -2301,7 +2297,7 @@ typedef integral_constant<bool, true> true_type;
};
template <typename T1, typename T2, typename = void>
struct common_type_2_impl
struct common_type_2_impl
: decay_conditional_result<const T1&, const T2&>
{
};
@ -2319,8 +2315,8 @@ typedef integral_constant<bool, true> true_type;
struct common_type<T1, T2>
: etl::conditional<etl::is_same<T1, typename etl::decay<T1>::type>::value&& etl::is_same<T2, typename etl::decay<T2>::type>::value,
private_common_type::common_type_2_impl<T1, T2>,
common_type<typename etl::decay<T2>::type,
typename etl::decay<T2>::type>>::type
common_type<typename etl::decay<T1>::type,
typename etl::decay<T2>::type>>::type
{
};
@ -2489,6 +2485,28 @@ typedef integral_constant<bool, true> true_type;
template <typename T, template <typename...> class Template>
inline constexpr bool is_specialization_v = etl::is_specialization<T, Template>::value;
#endif
//*********************************************
// is_constant_evaluated
ETL_CONSTEXPR inline bool is_constant_evaluated() ETL_NOEXCEPT
{
#if ETL_USING_CPP23
if consteval
{
return true;
}
else
{
return false;
}
#elif ETL_USING_BUILTIN_IS_CONSTANT_EVALUATED == 1
// fallback for C++20 on supported compilers
return __builtin_is_constant_evaluated();
#else
// default if unsupported
return false;
#endif
}
}
// Helper macros

View File

@ -98,6 +98,10 @@ SOFTWARE.
#define ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE (__has_builtin(__has_trivial_destructor) || __has_builtin(__is_trivially_destructible))
#endif
#if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE)
#define ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE (__has_builtin(__has_trivial_assign) || __has_builtin(__is_trivially_assignable))
#endif
#if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE)
#define ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE (__has_builtin(__has_trivial_copy) || __has_builtin(__is_trivially_copyable))
#endif

View File

@ -730,11 +730,11 @@ namespace etl
///\ingroup type_traits
/// Implemented by checking if type is convertible to an integer through static_cast
namespace private_type_traits
namespace private_type_traits
{
// Base case
template <typename T, typename = int>
struct is_convertible_to_int
struct is_convertible_to_int
: false_type
{
};
@ -743,7 +743,7 @@ namespace etl
// 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
: true_type
{
};
}
@ -753,7 +753,7 @@ namespace etl
: 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_reference<T>::value>
{
};
@ -1570,7 +1570,7 @@ typedef integral_constant<bool, true> true_type;
//***************************************************************************
/// Get the Nth base of a recursively inherited type.
/// Requires that the class has defined 'base_type'.
//***************************************************************************
//***************************************************************************
// Recursive definition of the type.
template <size_t Index, typename TType>
struct nth_base
@ -1997,7 +1997,7 @@ typedef integral_constant<bool, true> true_type;
#else
//***************************************************************************
/// is_constructible_
namespace private_type_traits
namespace private_type_traits
{
template <class, class T, class... Args>
struct is_constructible_ : etl::false_type {};
@ -2052,11 +2052,7 @@ typedef integral_constant<bool, true> true_type;
//*********************************************
// is_move_constructible
#if ETL_USING_CPP11
template <typename T> struct is_move_constructible : public is_constructible<T, typename etl::add_rvalue_reference<T>::type>{};
#else
template <typename T> struct is_move_constructible : public is_constructible<T, T>{};
#endif
#else
//*********************************************
// is_copy_constructible
@ -2155,19 +2151,29 @@ typedef integral_constant<bool, true> true_type;
};
#endif
#if ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE
#if ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE
//*********************************************
// is_trivially_copy_assignable
template <typename T>
struct is_trivially_copy_assignable
{
#if defined(ETL_COMPILER_GCC)
static ETL_CONSTANT bool value = __has_trivial_copy(T);
static ETL_CONSTANT bool value = __has_trivial_assign(T);
#else
static ETL_CONSTANT bool value = __is_trivially_copyable(T);
static ETL_CONSTANT bool value = __is_trivially_assignable(typename add_lvalue_reference<T>::type,
typename add_lvalue_reference<const T>::type);
#endif
};
#else
//*********************************************
// is_trivially_copy_assignable
template <typename T>
struct is_trivially_copy_assignable : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};
#endif
#if ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE
//*********************************************
// is_trivially_copyable
template <typename T>
@ -2180,21 +2186,12 @@ typedef integral_constant<bool, true> true_type;
#endif
};
#else
//*********************************************
// is_trivially_copy_assignable
template <typename T>
struct is_trivially_copy_assignable : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};
//*********************************************
// is_trivially_copyable
template <typename T>
struct is_trivially_copyable : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
{
};
#endif
#endif
template <typename T1, typename T2>
@ -2229,8 +2226,8 @@ typedef integral_constant<bool, true> true_type;
template<typename T, typename... TArgs>
inline constexpr bool is_constructible_v = etl::is_constructible<T, TArgs...>::value;
template<typename T, typename... TArgs>
inline constexpr bool is_default_constructible_v = etl::is_default_constructible<T, TArgs...>::value;
template<typename T>
inline constexpr bool is_default_constructible_v = etl::is_default_constructible<T>::value;
template<typename T>
inline constexpr bool is_copy_constructible_v = etl::is_copy_constructible<T>::value;
@ -2238,8 +2235,8 @@ typedef integral_constant<bool, true> true_type;
template<typename T>
inline constexpr bool is_move_constructible_v = etl::is_move_constructible<T>::value;
template <typename T>
inline constexpr bool is_trivially_constructible_v = etl::is_trivially_constructible<T>::value;
template <typename T, typename... TArgs>
inline constexpr bool is_trivially_constructible_v = etl::is_trivially_constructible<T, TArgs...>::value;
template <typename T>
inline constexpr bool is_trivially_copy_constructible_v = etl::is_trivially_copy_constructible<T>::value;
@ -2254,6 +2251,7 @@ typedef integral_constant<bool, true> true_type;
inline constexpr bool is_trivially_copyable_v = etl::is_trivially_copyable<T>::value;
#endif
#endif // ETL_USING_STL && ETL_USING_CPP11 && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS)
#if ETL_USING_CPP11
//*********************************************
@ -2292,7 +2290,7 @@ typedef integral_constant<bool, true> true_type;
};
template <typename T1, typename T2, typename = void>
struct common_type_2_impl
struct common_type_2_impl
: decay_conditional_result<const T1&, const T2&>
{
};
@ -2310,8 +2308,8 @@ typedef integral_constant<bool, true> true_type;
struct common_type<T1, T2>
: etl::conditional<etl::is_same<T1, typename etl::decay<T1>::type>::value&& etl::is_same<T2, typename etl::decay<T2>::type>::value,
private_common_type::common_type_2_impl<T1, T2>,
common_type<typename etl::decay<T2>::type,
typename etl::decay<T2>::type>>::type
common_type<typename etl::decay<T1>::type,
typename etl::decay<T2>::type>>::type
{
};