From 3e678aa81081161bc30da7af2fe70088ec786738 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 11 Mar 2026 07:47:16 +0000 Subject: [PATCH] Removed has_size_and_data traits, and move to type_traits.h Added ETL_ASSERT for for fixed extent constructors from iterator range and begin/size --- include/etl/span.h | 62 ++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index 26fbe8eb..f7ac7768 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -75,41 +75,6 @@ namespace etl template struct is_etl_array : is_etl_array {}; template struct is_etl_array : is_etl_array {}; -#if ETL_USING_CPP11 - template - struct has_size_and_data : etl::false_type {}; - - template - struct has_size_and_data())), - decltype(ETL_OR_STD17::data(etl::declval()))> > - : etl::true_type {}; -#else - template - struct has_size_and_data - { - private: - typedef char yes; - struct no { char dummy[2]; }; - - template - static yes test_size(char (*)[sizeof(&U::size)]); - - template - static no test_size(...); - - template - static yes test_data(char (*)[sizeof(&U::data)]); - - template - static no test_data(...); - - public: - - static const bool value = (sizeof(test_size(0)) == sizeof(yes)) && - (sizeof(test_data(0)) == sizeof(yes)); - }; -#endif - //*************************************************************************** // Tag to indicate a class is a span. //*************************************************************************** @@ -192,11 +157,17 @@ namespace etl } }; + //*************************************************************************** + ///\ingroup span + /// Tag to indicate a class is a span. + /// Deprecated, use is_span trait instead. + class span_tag {}; + //*************************************************************************** /// Span - Fixed Extent //*************************************************************************** template - class span + class span : public span_tag { public: @@ -240,19 +211,23 @@ namespace etl /// Construct from iterator + size //************************************************************************* template - explicit ETL_CONSTEXPR span(const TIterator begin_, const size_t /*size_*/) ETL_NOEXCEPT + explicit ETL_CONSTEXPR span(const TIterator begin_, const size_t size_) ETL_NOEXCEPT_FROM(ETL_NOT_USING_EXCEPTIONS) : pbegin(etl::to_address(begin_)) { + ETL_ASSERT(size == Extent, ETL_ERROR(span_size_mismatch)); + (void)size_; } //************************************************************************* /// Construct from iterators //************************************************************************* template - ETL_CONSTEXPR span(const TIteratorBegin begin_, const TIteratorEnd /*end_*/, - typename etl::enable_if::value, void>::type* = 0) ETL_NOEXCEPT + ETL_CONSTEXPR span(const TIteratorBegin begin_, const TIteratorEnd end_, + typename etl::enable_if::value, void>::type* = 0) ETL_NOEXCEPT_FROM(ETL_NOT_USING_EXCEPTIONS) : pbegin(etl::to_address(begin_)) { + ETL_ASSERT(etl::distance(begin_, end_) == Extent, ETL_ERROR(span_size_mismatch)); + (void)end_; } //************************************************************************* @@ -274,7 +249,8 @@ namespace etl !etl::is_etl_array::type>::value && !etl::is_pointer::type>::value && !etl::is_array::value && - has_size_and_data::value && + has_size::value && + has_data::value && etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) : pbegin(a.data()) { @@ -290,8 +266,8 @@ namespace etl !etl::is_std_array::type>::value && !etl::is_etl_array::type>::value && !etl::is_pointer::type>::value && - !etl::is_array::value&& - has_size_and_data::value && + has_size::value && + has_data::value && etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) : pbegin(a.data()) { @@ -720,7 +696,7 @@ namespace etl /// Span - Dynamic Extent //*************************************************************************** template - class span + class span : public span_tag { public: