[libcxx-commits] [libcxx] r354805 - LWG3101 - span's Container constructors need another constraint. Reviewed as https://reviews.llvm.org/D57058.
Marshall Clow via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 25 10:32:58 PST 2019
Author: marshall
Date: Mon Feb 25 10:32:57 2019
New Revision: 354805
URL: http://llvm.org/viewvc/llvm-project?rev=354805&view=rev
Log:
LWG3101 - span's Container constructors need another constraint. Reviewed as https://reviews.llvm.org/D57058.
Modified:
libcxx/trunk/include/span
libcxx/trunk/test/std/containers/views/span.cons/container.fail.cpp
libcxx/trunk/test/std/containers/views/span.cons/container.pass.cpp
Modified: libcxx/trunk/include/span
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/span?rev=354805&r1=354804&r2=354805&view=diff
==============================================================================
--- libcxx/trunk/include/span (original)
+++ libcxx/trunk/include/span Mon Feb 25 10:32:57 2019
@@ -225,20 +225,6 @@ public:
_LIBCPP_INLINE_VISIBILITY constexpr span( array<value_type, _Extent>& __arr) noexcept : __data{__arr.data()} {}
_LIBCPP_INLINE_VISIBILITY constexpr span(const array<value_type, _Extent>& __arr) noexcept : __data{__arr.data()} {}
- template <class _Container>
- inline _LIBCPP_INLINE_VISIBILITY
- constexpr span( _Container& __c,
- enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr)
- : __data{_VSTD::data(__c)}
- { _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (container)"); }
-
- template <class _Container>
- inline _LIBCPP_INLINE_VISIBILITY
- constexpr span(const _Container& __c,
- enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr)
- : __data{_VSTD::data(__c)}
- { _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (const container)"); }
-
template <class _OtherElementType>
inline _LIBCPP_INLINE_VISIBILITY
constexpr span(const span<_OtherElementType, _Extent>& __other,
Modified: libcxx/trunk/test/std/containers/views/span.cons/container.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/views/span.cons/container.fail.cpp?rev=354805&r1=354804&r2=354805&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/views/span.cons/container.fail.cpp (original)
+++ libcxx/trunk/test/std/containers/views/span.cons/container.fail.cpp Mon Feb 25 10:32:57 2019
@@ -16,6 +16,7 @@
// constexpr span(const Container& cont);
//
// Remarks: These constructors shall not participate in overload resolution unless:
+// â extent == dynamic_extent,
// â Container is not a specialization of span,
// â Container is not a specialization of array,
// â is_array_v<Container> is false,
@@ -69,37 +70,28 @@ int main(int, char**)
// Making non-const spans from const sources (a temporary binds to `const &`)
{
std::span<int> s1{IsAContainer<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
- std::span<int, 0> s2{IsAContainer<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}
std::span<int> s3{std::vector<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
- std::span<int, 0> s4{std::vector<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}
}
// Missing size and/or data
{
std::span<const int> s1{NotAContainerNoData<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
- std::span<const int, 0> s2{NotAContainerNoData<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}}
std::span<const int> s3{NotAContainerNoSize<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
- std::span<const int, 0> s4{NotAContainerNoSize<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}}
std::span<const int> s5{NotAContainerPrivate<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
- std::span<const int, 0> s6{NotAContainerPrivate<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}}
// Again with the standard containers
std::span<const int> s11{std::deque<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
- std::span<const int, 0> s12{std::deque<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}}
std::span<const int> s13{std::list<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
- std::span<const int, 0> s14{std::list<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}}
std::span<const int> s15{std::forward_list<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
- std::span<const int, 0> s16{std::forward_list<int>()}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}}
}
// Not the same type
{
IsAContainer<int> c;
std::span<float> s1{c}; // expected-error {{no matching constructor for initialization of 'std::span<float>'}}
- std::span<float, 0> s2{c}; // expected-error {{no matching constructor for initialization of 'std::span<float, 0>'}}
}
-// CV wrong (dynamically sized)
+// CV wrong
{
IsAContainer<const int> c;
IsAContainer<const volatile int> cv;
@@ -114,19 +106,10 @@ int main(int, char**)
std::span< volatile int> s7{cv}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
}
-// CV wrong (statically sized)
+// statically sized
{
- IsAContainer<const int> c;
- IsAContainer<const volatile int> cv;
- IsAContainer< volatile int> v;
-
- std::span< int,1> s1{c}; // expected-error {{no matching constructor for initialization of 'std::span<int, 1>'}}
- std::span< int,1> s2{v}; // expected-error {{no matching constructor for initialization of 'std::span<int, 1>'}}
- std::span< int,1> s3{cv}; // expected-error {{no matching constructor for initialization of 'std::span<int, 1>'}}
- std::span<const int,1> s4{v}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 1>'}}
- std::span<const int,1> s5{cv}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 1>'}}
- std::span< volatile int,1> s6{c}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 1>'}}
- std::span< volatile int,1> s7{cv}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 1>'}}
+ IsAContainer<int> c;
+ std::span<int,1> s1{c}; // expected-error {{no matching constructor for initialization of 'std::span<int, 1>'}}
}
Modified: libcxx/trunk/test/std/containers/views/span.cons/container.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/views/span.cons/container.pass.cpp?rev=354805&r1=354804&r2=354805&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/views/span.cons/container.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/views/span.cons/container.pass.cpp Mon Feb 25 10:32:57 2019
@@ -16,6 +16,7 @@
// constexpr span(const Container& cont);
//
// Remarks: These constructors shall not participate in overload resolution unless:
+// â extent == dynamic_extent,
// â Container is not a specialization of span,
// â Container is not a specialization of array,
// â is_array_v<Container> is false,
@@ -48,17 +49,12 @@ void checkCV()
{
std::vector<int> v = {1,2,3};
-// Types the same (dynamic sized)
+// Types the same
{
std::span< int> s1{v}; // a span< int> pointing at int.
}
-// Types the same (static sized)
- {
- std::span< int,3> s1{v}; // a span< int> pointing at int.
- }
-
-// types different (dynamic sized)
+// types different
{
std::span<const int> s1{v}; // a span<const int> pointing at int.
std::span< volatile int> s2{v}; // a span< volatile int> pointing at int.
@@ -66,24 +62,12 @@ void checkCV()
std::span<const volatile int> s4{v}; // a span<const volatile int> pointing at int.
}
-// types different (static sized)
- {
- std::span<const int,3> s1{v}; // a span<const int> pointing at int.
- std::span< volatile int,3> s2{v}; // a span< volatile int> pointing at int.
- std::span< volatile int,3> s3{v}; // a span< volatile int> pointing at const int.
- std::span<const volatile int,3> s4{v}; // a span<const volatile int> pointing at int.
- }
-
// Constructing a const view from a temporary
{
std::span<const int> s1{IsAContainer<int>()};
- std::span<const int, 0> s2{IsAContainer<int>()};
std::span<const int> s3{std::vector<int>()};
- std::span<const int, 0> s4{std::vector<int>()};
(void) s1;
- (void) s2;
(void) s3;
- (void) s4;
}
}
@@ -92,11 +76,8 @@ template <typename T>
constexpr bool testConstexprSpan()
{
constexpr IsAContainer<const T> val{};
- std::span<const T> s1{val};
- std::span<const T, 1> s2{val};
- return
- s1.data() == val.getV() && s1.size() == 1
- && s2.data() == val.getV() && s2.size() == 1;
+ std::span<const T> s1{val};
+ return s1.data() == val.getV() && s1.size() == 1;
}
@@ -107,12 +88,8 @@ void testRuntimeSpan()
const IsAContainer<T> cVal;
std::span<T> s1{val};
std::span<const T> s2{cVal};
- std::span<T, 1> s3{val};
- std::span<const T, 1> s4{cVal};
assert(s1.data() == val.getV() && s1.size() == 1);
assert(s2.data() == cVal.getV() && s2.size() == 1);
- assert(s3.data() == val.getV() && s3.size() == 1);
- assert(s4.data() == cVal.getV() && s4.size() == 1);
}
struct A{};
More information about the libcxx-commits
mailing list