Moved and split has_size_and_data in span.h to has_size & has_data in type_traits.h

This commit is contained in:
John Wellbelove 2026-03-11 07:43:48 +00:00
parent 779c9f297e
commit c6bc7c1c43
2 changed files with 118 additions and 10 deletions

View File

@ -765,11 +765,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
{
};
@ -778,7 +778,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
{
};
}
@ -788,7 +788,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>
{
};
@ -1647,7 +1647,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
@ -2192,7 +2192,7 @@ typedef integral_constant<bool, true> true_type;
#if ETL_USING_CPP11
//***************************************************************************
/// is_constructible
namespace private_type_traits
namespace private_type_traits
{
template <class, class T, class... TArgs>
struct is_constructible_ : etl::false_type {};
@ -2371,7 +2371,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&>
{
};
@ -2716,7 +2716,7 @@ typedef integral_constant<bool, true> true_type;
struct is_member_pointer_helper<T TObject::*> : etl::true_type {};
}
template<typename T>
template<typename T>
struct is_member_pointer : private_type_traits::is_member_pointer_helper<typename etl::remove_cv<T>::type> {};
#if ETL_USING_CPP17
@ -2809,10 +2809,10 @@ typedef integral_constant<bool, true> true_type;
//***************************************************************************
namespace private_type_traits
{
template<typename>
template<typename>
struct is_member_object_pointer_helper : public etl::false_type {};
template<typename T, typename TObject>
template<typename T, typename TObject>
struct is_member_object_pointer_helper<T TObject::*> : public etl::negation<etl::is_function<T>> {};
}
@ -3034,6 +3034,60 @@ typedef integral_constant<bool, true> true_type;
};
#endif
#if ETL_USING_CPP11
template <typename, typename = void>
struct has_size : etl::false_type {};
template <typename T>
struct has_size<T, void_t<decltype(etl::declval<T>().size())> >
: etl::true_type {};
#else
template <typename T>
struct has_size
{
private:
typedef char yes;
struct no { char dummy[2]; };
template <typename U>
static yes test_size(char (*)[sizeof(&U::size)]);
template <typename U>
static no test_size(...);
public:
static const bool value = (sizeof(test_size<T>(0)) == sizeof(yes));
};
#endif
#if ETL_USING_CPP11
template <typename, typename = void>
struct has_data : etl::false_type {};
template <typename T>
struct has_data<T, void_t<decltype(etl::declval<T>().data())> >
: etl::true_type {};
#else
template <typename T>
struct has_data
{
private:
typedef char yes;
struct no { char dummy[2]; };
template <typename U>
static yes test_data(char (*)[sizeof(&U::data)]);
template <typename U>
static no test_data(...);
public:
static const bool value = (sizeof(test_data<T>(0)) == sizeof(yes));
};
#endif
}
// Helper macros

View File

@ -3099,6 +3099,60 @@ typedef integral_constant<bool, true> true_type;
};
#endif
#if ETL_USING_CPP11
template <typename, typename = void>
struct has_size : etl::false_type {};
template <typename T>
struct has_size<T, void_t<decltype(etl::declval<T>().size())> >
: etl::true_type {};
#else
template <typename T>
struct has_size
{
private:
typedef char yes;
struct no { char dummy[2]; };
template <typename U>
static yes test_size(char (*)[sizeof(&U::size)]);
template <typename U>
static no test_size(...);
public:
static const bool value = (sizeof(test_size<T>(0)) == sizeof(yes));
};
#endif
#if ETL_USING_CPP11
template <typename, typename = void>
struct has_data : etl::false_type {};
template <typename T>
struct has_data<T, void_t<decltype(etl::declval<T>().data())> >
: etl::true_type {};
#else
template <typename T>
struct has_data
{
private:
typedef char yes;
struct no { char dummy[2]; };
template <typename U>
static yes test_data(char (*)[sizeof(&U::data)]);
template <typename U>
static no test_data(...);
public:
static const bool value = (sizeof(test_data<T>(0)) == sizeof(yes));
};
#endif
}
// Helper macros