From: Jonathan Wakely Date: Tue, 18 Feb 2020 13:12:44 +0000 (+0000) Subject: libstdc++: Fix and simplify constraints on std::span constructors X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d6c9e372372ee78283a21651313fce965d22274d;p=gcc.git libstdc++: Fix and simplify constraints on std::span constructors This makes the constraints consistent with the pre-Prague working paper. * include/std/span (span::__is_compatible_array): Simplify alias template by using requires-clause. (span::__is_compatible_ref): New alias template for constraining constructors. (span::__is_compatible_iterator, span::__is_compatible_range): Remove. (span(It, size_type), span(It, End)): Use __is_compatible_ref. (span(T(&)[N], span(array&), span(const array&)): Remove redundant parentheses. (span(R&&)): Add missing constraints. --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6ae3955d2ce..de0995264a0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,15 @@ 2020-02-18 Jonathan Wakely + * include/std/span (span::__is_compatible_array): Simplify alias + template by using requires-clause. + (span::__is_compatible_ref): New alias template for constraining + constructors. + (span::__is_compatible_iterator, span::__is_compatible_range): Remove. + (span(It, size_type), span(It, End)): Use __is_compatible_ref. + (span(T(&)[N], span(array&), span(const array&)): Remove + redundant parentheses. + (span(R&&)): Add missing constraints. + * include/std/span (span): Reorder members and rename template parameters to match declarations in the C++2a working paper. diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span index feb1c1f46ad..21114f1e038 100644 --- a/libstdc++-v3/include/std/span +++ b/libstdc++-v3/include/std/span @@ -123,20 +123,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // _GLIBCXX_RESOLVE_LIB_DEFECTS // 3255. span's array constructor is too strict template - using __is_compatible_array = __and_< - bool_constant<(_Extent == dynamic_extent || _ArrayExtent == _Extent)>, - __is_array_convertible<_Type, _Tp>>; + requires (_Extent == dynamic_extent || _ArrayExtent == _Extent) + using __is_compatible_array = __is_array_convertible<_Type, _Tp>; - template> - using __is_compatible_iterator = __and_< - bool_constant>, - is_lvalue_reference>, - is_same, remove_cvref_t<_Ref>>, - __is_array_convertible<_Type, remove_reference_t<_Ref>>>; - - template - using __is_compatible_range - = __is_compatible_iterator>; + template + using __is_compatible_ref + = __is_array_convertible<_Type, remove_reference_t<_Ref>>; public: // member types @@ -165,7 +157,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { } template - requires (__is_compatible_iterator<_It>::value) + requires __is_compatible_ref>::value constexpr span(_It __first, size_type __count) noexcept @@ -173,8 +165,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __glibcxx_assert(_Extent == dynamic_extent || __count == _Extent); } template _End> - requires (__is_compatible_iterator<_It>::value) - && (!is_convertible_v<_End, size_type>) + requires __is_compatible_ref>::value + && (!is_convertible_v<_End, size_type>) constexpr span(_It __first, _End __last) noexcept(noexcept(__last - __first)) @@ -186,32 +178,34 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - requires (__is_compatible_array<_Tp, _ArrayExtent>::value) + requires __is_compatible_array<_Tp, _ArrayExtent>::value constexpr span(_Tp (&__arr)[_ArrayExtent]) noexcept : span(static_cast(__arr), _ArrayExtent) { } template - requires (__is_compatible_array<_Tp, _ArrayExtent>::value) + requires __is_compatible_array<_Tp, _ArrayExtent>::value constexpr span(array<_Tp, _ArrayExtent>& __arr) noexcept : span(static_cast(__arr.data()), _ArrayExtent) { } template - requires (__is_compatible_array::value) + requires __is_compatible_array::value constexpr span(const array<_Tp, _ArrayExtent>& __arr) noexcept : span(static_cast(__arr.data()), _ArrayExtent) { } - template + template requires (_Extent == dynamic_extent) + && ranges::contiguous_range<_Range> && ranges::sized_range<_Range> + && (ranges::safe_range<_Range> || is_const_v) && (!__detail::__is_std_span>::value) && (!__detail::__is_std_array>::value) - && (!is_array_v>) - && (__is_compatible_range<_Range>::value) + && (!is_array_v>) + && __is_compatible_ref>::value constexpr span(_Range&& __range) noexcept(noexcept(ranges::data(__range))