diff --git a/include/gsl/span b/include/gsl/span index 20f4237..62591df 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -418,7 +418,8 @@ public: // "Dependent" is needed to make "std::enable_if_t" SFINAE, since "std::enable_if_t" is ill-formed when Extent is greater than 0. - class = std::enable_if_t<(Dependent || Extent == 0 || Extent == dynamic_extent)>> + class = std::enable_if_t<(Dependent || + details::is_allowed_extent_conversion<0, Extent>::value)>> constexpr span() noexcept : storage_(nullptr, details::extent_type<0>()) {} @@ -430,36 +431,31 @@ public: constexpr span(pointer firstElem, pointer lastElem) noexcept : storage_(firstElem, static_cast(std::distance(firstElem, lastElem))) { - if (Extent != dynamic_extent) { Expects(lastElem - firstElem == static_cast(Extent)); } + if (Extent != dynamic_extent) + { Expects(lastElem - firstElem == static_cast(Extent)); } } - template + template ::value, int> = 0> constexpr span(element_type (&arr)[N]) noexcept : storage_(KnownNotNull{std::addressof(arr[0])}, details::extent_type()) {} - template = 0> - constexpr span(std::array& arr) noexcept + template ::value, int> = 0> + constexpr span(std::array& arr) noexcept : storage_(KnownNotNull{arr.data()}, details::extent_type()) {} - template ::value), + template ::value && + details::is_allowed_element_type_conversion::value), int> = 0> constexpr span(const std::array& arr) noexcept : storage_(KnownNotNull{arr.data()}, details::extent_type()) {} - constexpr span(std::array&) noexcept - : storage_(static_cast(nullptr), details::extent_type<0>()) - {} - - constexpr span(const std::array&) noexcept - : storage_(static_cast(nullptr), details::extent_type<0>()) - {} - // NB: the SFINAE here uses .data() as a incomplete/imperfect proxy for the requirement // on Container to be a contiguous sequence container. template ::value && !details::is_span::value && + !details::is_std_array::value && std::is_convertible::value && std::is_convertible().data()), pointer>::value>> constexpr span(const Container& cont) noexcept : span(cont.data(), cont.size()) @@ -677,7 +674,7 @@ private: template constexpr span make_subspan(size_type offset, size_type count, - subspan_selector) const + subspan_selector) const { const span tmp(*this); return tmp.subspan(offset, count); @@ -686,8 +683,8 @@ private: // clang-format off GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute // clang-format on - constexpr span make_subspan(size_type offset, size_type count, - subspan_selector) const + constexpr span + make_subspan(size_type offset, size_type count, subspan_selector) const { Expects(size() >= offset);