aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/span
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-09-30 12:52:08 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2019-09-30 12:52:08 +0100
commit582c57a17eaf02e90492145cd7217bda5499076b (patch)
tree2c75c44849d88b4261c0cf454cf0118a4534976e /libstdc++-v3/include/std/span
parent6438d29fb1a31c95b9d652117a79dde2f9e4ad6f (diff)
downloadgcc-582c57a17eaf02e90492145cd7217bda5499076b.zip
gcc-582c57a17eaf02e90492145cd7217bda5499076b.tar.gz
gcc-582c57a17eaf02e90492145cd7217bda5499076b.tar.bz2
Implement LWG 3255 for std::span constructors
Also fix the constraints on span(Container&) and span(const Container&) constructors so that they aren't used for const spans or const arrays. * include/std/span (span(element_type(&)[N])) (span(array<value_type, N>&), span(const array<value_type, N>&)): Deduce array element type to allow safe const conversions (LWG 3255). [!_GLIBCXX_P1394] (span(Container&), span(const Container&)): Use remove_cv_t on arguments to __is_std_span and __is_std_array. * testsuite/23_containers/span/lwg3255.cc: New test. From-SVN: r276298
Diffstat (limited to 'libstdc++-v3/include/std/span')
-rw-r--r--libstdc++-v3/include/std/span45
1 files changed, 24 insertions, 21 deletions
diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span
index 1a0d61c..fcec22a 100644
--- a/libstdc++-v3/include/std/span
+++ b/libstdc++-v3/include/std/span
@@ -125,6 +125,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
using __is_compatible = is_convertible<_Tp(*)[], _Type(*)[]>;
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3255. span's array constructor is too strict
+ template<typename _Tp, size_t _ArrayExtent,
+ typename = enable_if_t<_Extent == dynamic_extent
+ || _ArrayExtent == _Extent>>
+ using __is_compatible_array = __is_compatible<_Tp>;
+
public:
// member types
using value_type = remove_cv_t<_Type>;
@@ -149,9 +156,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// constructors
- template <typename _Dummy = _Type,
- enable_if_t<is_same_v<_Dummy, _Type>
- && (_Extent == dynamic_extent || _Extent == 0)>* = nullptr>
+ template<bool _DefaultConstructible = (_Extent + 1u) <= 1u,
+ enable_if_t<_DefaultConstructible>* = nullptr>
constexpr
span() noexcept : _M_extent(0), _M_ptr(nullptr)
{ }
@@ -159,28 +165,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr
span(const span&) noexcept = default;
- template<size_t _ArrayExtent,
- enable_if_t<_Extent == dynamic_extent || _ArrayExtent == _Extent>*
- = nullptr>
+ template<typename _Tp, size_t _ArrayExtent,
+ typename = _Require<__is_compatible_array<_Tp, _ArrayExtent>>>
constexpr
- span(element_type (&__arr)[_ArrayExtent]) noexcept
+ span(_Tp (&__arr)[_ArrayExtent]) noexcept
: span(static_cast<pointer>(__arr), _ArrayExtent)
{ }
- template<size_t _ArrayExtent,
- enable_if_t<_Extent == dynamic_extent || _ArrayExtent == _Extent>*
- = nullptr>
+ template<typename _Tp, size_t _ArrayExtent,
+ typename = _Require<__is_compatible_array<_Tp, _ArrayExtent>>>
constexpr
- span(array<value_type, _ArrayExtent>& __arr) noexcept
- : span(__arr.data(), _ArrayExtent)
+ span(array<_Tp, _ArrayExtent>& __arr) noexcept
+ : span(static_cast<pointer>(__arr.data()), _ArrayExtent)
{ }
- template<size_t _ArrayExtent,
- enable_if_t<_Extent == dynamic_extent || _ArrayExtent == _Extent>*
- = nullptr>
+ template<typename _Tp, size_t _ArrayExtent,
+ typename = _Require<__is_compatible_array<_Tp, _ArrayExtent>>>
constexpr
- span(const array<value_type, _ArrayExtent>& __arr) noexcept
- : span(__arr.data(), _ArrayExtent)
+ span(const array<_Tp, _ArrayExtent>& __arr) noexcept
+ : span(static_cast<pointer>(__arr.data()), _ArrayExtent)
{ }
// NOTE: when the time comes, and P1394 -
@@ -271,8 +274,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
public:
template<typename _Container, typename = _Require<
bool_constant<_Extent == dynamic_extent>,
- __not_<__detail::__is_std_span<_Container>>,
- __not_<__detail::__is_std_array<_Container>>,
+ __not_<__detail::__is_std_span<remove_cv_t<_Container>>>,
+ __not_<__detail::__is_std_array<remove_cv_t<_Container>>>,
__not_<is_array<_Container>>,
__is_compatible_container<_Container>>>
constexpr
@@ -283,8 +286,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Container, typename = _Require<
bool_constant<_Extent == dynamic_extent>,
- __not_<__detail::__is_std_span<_Container>>,
- __not_<__detail::__is_std_array<_Container>>,
+ __not_<__detail::__is_std_span<remove_cv_t<_Container>>>,
+ __not_<__detail::__is_std_array<remove_cv_t<_Container>>>,
__not_<is_array<_Container>>,
__is_compatible_container<const _Container>>>
constexpr