From 4097b9d956833c3b74b01b1faa784259bd20adf2 Mon Sep 17 00:00:00 2001 From: Marc Emmers Date: Mon, 9 Nov 2020 08:55:55 +0100 Subject: [PATCH] Add container constructor and make_span --- platform/cxxsupport/mstd_span | 57 ++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/platform/cxxsupport/mstd_span b/platform/cxxsupport/mstd_span index 7703f3e68e..79dd22d8cf 100644 --- a/platform/cxxsupport/mstd_span +++ b/platform/cxxsupport/mstd_span @@ -53,6 +53,41 @@ public: ElementType* _data; size_t _size; }; + +template +struct is_span: false_type {}; + +template +struct is_span>: true_type {}; + +template +struct is_std_array: false_type {}; + +template +struct is_std_array>: true_type {}; + +template +struct has_size : std::false_type {}; + +template +struct has_size()))>>: + std::true_type {}; + +template +struct has_data : std::false_type {}; + +template +struct has_data()))>>: + std::true_type {}; + +template> +struct is_container{ + static constexpr bool value = + not is_span::value && not is_std_array::value && + not std::is_array::value && has_size::value && + has_data::value; +}; + template using iterator_t = decltype(mstd::begin(std::declval())); @@ -140,10 +175,14 @@ public: _storage(arr.data(), N) {} - /* TODO - template - constexpr explicit(extent != dynamic_extent) span(R&& r) - */ + template::value && + detail::is_compatible::value, int> = 0> + constexpr span(R&& r) : + _storage( mstd::data( r ), mstd::size( r )) + { + MBED_ASSERT(extent == dynamic_extent || extent == mstd::size( r )); + } constexpr span(const span& other) noexcept = default; @@ -307,13 +346,17 @@ constexpr span make_span(const array(arr); } -/* TODO template -constexpr span make_span(R&& cont) +constexpr span make_span(R& cont) +{ + return {cont}; +} + +template +constexpr span make_span(const R& cont) { return {cont}; } -*/ } // namespace mstd