diff --git a/include/etl/span.h b/include/etl/span.h index f1077ea77..122a251c6 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -377,6 +377,16 @@ namespace etl pointer pbegin; }; + //************************************************************************* + /// Pseudo constructor for constructing from C array without explicitly + /// specifying type and size + //************************************************************************* + template + ETL_CONSTEXPR span make_span(T (&data)[Extent]) + { + return span(data); + } + //*************************************************************************** /// Span - Dynamic Extent //*************************************************************************** @@ -700,6 +710,26 @@ namespace etl pointer pend; }; + //************************************************************************* + /// Pseudo constructor for constructing from container without explicitly + /// specifying type and size + //************************************************************************* + template + ETL_CONSTEXPR span make_span(T& data) + { + return span(data); + } + + //************************************************************************* + /// Pseudo constructor for constructing from const container without + /// explicitly specifying type and size + //************************************************************************* + template + ETL_CONSTEXPR span make_span(const T& data) + { + return span(data); + } + template ETL_CONSTANT size_t span::extent; diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index 3d7df1ec0..c2df0e5ae 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -1205,6 +1205,25 @@ namespace } } + //************************************************************************* + TEST(test_make_span_container) + { + { + auto s = etl::make_span(etldata); + + CHECK_EQUAL(s.size(), 10); + View view(etldata); + CHECK_TRUE(etl::equal(s, view)); + } + { + auto s = etl::make_span(cetldata); + + CHECK_EQUAL(s.size(), 10); + View view(etldata); + CHECK_TRUE(etl::equal(s, view)); + } + } + #include "etl/private/diagnostic_pop.h" }; } diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 157170a09..870eb51cd 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -1123,6 +1123,25 @@ namespace } } + //************************************************************************* + TEST(test_make_span_c_array) + { + { + auto s = etl::make_span(cdata); + + CHECK_EQUAL(s.size(), 10); + View view(etldata); + CHECK_TRUE(etl::equal(s, view)); + } + { + auto s = etl::make_span(ccdata); + + CHECK_EQUAL(s.size(), 10); + View view(etldata); + CHECK_TRUE(etl::equal(s, view)); + } + } + #include "etl/private/diagnostic_pop.h" }; }