diff --git a/platform/cxxsupport/mstd_span b/platform/cxxsupport/mstd_span index 7703f3e..79dd22d 100644 --- a/platform/cxxsupport/mstd_span +++ b/platform/cxxsupport/mstd_span @@ -53,6 +53,41 @@ 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 @@ _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 @@ return span(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