From b2d12fac88a7388bedb8422cb921b39dceb4ce71 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 15:16:06 -0700 Subject: [PATCH 01/18] P1989R2 Range Constructor For `string_view` --- stl/inc/xstring | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/stl/inc/xstring b/stl/inc/xstring index 36cef22456a..68292f29d46 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -17,6 +17,10 @@ #include #endif // _HAS_CXX17 +#if _HAS_CXX23 +#include +#endif // _HAS_CXX23 + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -1278,6 +1282,28 @@ public: #endif // _CONTAINER_DEBUG_LEVEL > 0 } +#if _HAS_CXX23 + // clang-format off + template + concept _Has_compatible_traits = !requires { + typename _Range::traits_type; + } || same_as::traits_type, _Traits>; + // clang-format on + + // clang-format off + template <_RANGES contiguous_range _Range> + requires _RANGES sized_range<_Range> + && same_as<_RANGES range_value_t<_Range>, _Elem> + && !is_convertible_v + && !requires(remove_reference_t<_Range> & _Rng) { + _Rng.operator basic_string_view<_Elem, _Traits>(); + } && _Has_compatible_traits<_Range> + constexpr basic_string_view(_Range&& _Rng) noexcept( + noexcept(_RANGES data(_Rng)) && noexcept(_RANGES size(_Rng))) // strengthened + : _Mydata(_RANGES data(_Rng)), _Mysize(_RANGES size(_Rng)) {} + // clang-format on +#endif // _HAS_CXX23 + #ifdef __cpp_lib_concepts // clang-format off template _Se> From 93cf217dfe0f51d1c3ada9e0a596a5aeea2dd6e0 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 15:20:31 -0700 Subject: [PATCH 02/18] Move helper concept to above `basic_string_view` --- stl/inc/xstring | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 68292f29d46..2a9cc5ca8d6 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1238,6 +1238,15 @@ struct pointer_traits<_String_view_iterator<_Traits>> { }; #endif // _HAS_CXX20 +#if _HAS_CXX23 +// clang-format off +template +concept _Has_compatible_traits = !requires { + typename _Range::traits_type; +} || same_as::traits_type, _Traits>; +// clang-format on +#endif // _HAS_CXX23 + // CLASS TEMPLATE basic_string_view template @@ -1283,13 +1292,6 @@ public: } #if _HAS_CXX23 - // clang-format off - template - concept _Has_compatible_traits = !requires { - typename _Range::traits_type; - } || same_as::traits_type, _Traits>; - // clang-format on - // clang-format off template <_RANGES contiguous_range _Range> requires _RANGES sized_range<_Range> @@ -1297,7 +1299,7 @@ public: && !is_convertible_v && !requires(remove_reference_t<_Range> & _Rng) { _Rng.operator basic_string_view<_Elem, _Traits>(); - } && _Has_compatible_traits<_Range> + } && _Has_compatible_traits<_Range, _Traits> constexpr basic_string_view(_Range&& _Rng) noexcept( noexcept(_RANGES data(_Rng)) && noexcept(_RANGES size(_Rng))) // strengthened : _Mydata(_RANGES data(_Rng)), _Mysize(_RANGES size(_Rng)) {} From 8986a22ce8b1374ea1fce3bb7003fd22dec96c6b Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 15:43:15 -0700 Subject: [PATCH 03/18] Fixed syntax errors --- stl/inc/xstring | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 2a9cc5ca8d6..a5bd9ad041b 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1296,10 +1296,10 @@ public: template <_RANGES contiguous_range _Range> requires _RANGES sized_range<_Range> && same_as<_RANGES range_value_t<_Range>, _Elem> - && !is_convertible_v - && !requires(remove_reference_t<_Range> & _Rng) { + && (!is_convertible_v<_Range, const _Elem*>) + && (!requires(remove_reference_t<_Range> & _Rng) { _Rng.operator basic_string_view<_Elem, _Traits>(); - } && _Has_compatible_traits<_Range, _Traits> + }) && _Has_compatible_traits<_Range, _Traits> constexpr basic_string_view(_Range&& _Rng) noexcept( noexcept(_RANGES data(_Rng)) && noexcept(_RANGES size(_Rng))) // strengthened : _Mydata(_RANGES data(_Rng)), _Mysize(_RANGES size(_Rng)) {} From 6739fb83defd06e443dc782e0dcd397efd9fc058 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 16:07:19 -0700 Subject: [PATCH 04/18] Reorder ranges ctor according tot he Standard --- stl/inc/xstring | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index a5bd9ad041b..eeef3c185da 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1291,6 +1291,15 @@ public: #endif // _CONTAINER_DEBUG_LEVEL > 0 } +#ifdef __cpp_lib_concepts + // clang-format off + template _Se> + requires (is_same_v, _Elem> && !is_convertible_v<_Se, size_type>) + constexpr basic_string_view(_It _First, _Se _Last) noexcept(noexcept(_Last - _First)) // strengthened + : _Mydata(_STD to_address(_First)), _Mysize(static_cast(_Last - _First)) {} + // clang-format on +#endif // __cpp_lib_concepts + #if _HAS_CXX23 // clang-format off template <_RANGES contiguous_range _Range> @@ -1306,15 +1315,6 @@ public: // clang-format on #endif // _HAS_CXX23 -#ifdef __cpp_lib_concepts - // clang-format off - template _Se> - requires (is_same_v, _Elem> && !is_convertible_v<_Se, size_type>) - constexpr basic_string_view(_It _First, _Se _Last) noexcept(noexcept(_Last - _First)) // strengthened - : _Mydata(_STD to_address(_First)), _Mysize(static_cast(_Last - _First)) {} - // clang-format on -#endif // __cpp_lib_concepts - _NODISCARD constexpr const_iterator begin() const noexcept { #if _ITERATOR_DEBUG_LEVEL >= 1 return const_iterator(_Mydata, _Mysize, 0); From ba7ee272a6fd743716c8478030482662d6a05b1c Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 16:54:33 -0700 Subject: [PATCH 05/18] Guard against EDG --- stl/inc/xstring | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index eeef3c185da..a8c26490404 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1300,20 +1300,23 @@ public: // clang-format on #endif // __cpp_lib_concepts -#if _HAS_CXX23 +#if _HAS_CXX23 && defined(___cpp_lib_concepts) // clang-format off template <_RANGES contiguous_range _Range> requires _RANGES sized_range<_Range> && same_as<_RANGES range_value_t<_Range>, _Elem> && (!is_convertible_v<_Range, const _Elem*>) - && (!requires(remove_reference_t<_Range> & _Rng) { + && (!requires(remove_reference_t<_Range>& _Rng) { _Rng.operator basic_string_view<_Elem, _Traits>(); - }) && _Has_compatible_traits<_Range, _Traits> + }) + && ((!requires { + typename remove_reference_t<_Range>::traits_type; + }) || same_as::traits_type, _Traits>) constexpr basic_string_view(_Range&& _Rng) noexcept( noexcept(_RANGES data(_Rng)) && noexcept(_RANGES size(_Rng))) // strengthened : _Mydata(_RANGES data(_Rng)), _Mysize(_RANGES size(_Rng)) {} // clang-format on -#endif // _HAS_CXX23 +#endif // _HAS_CXX23 && defined(___cpp_lib_concepts) _NODISCARD constexpr const_iterator begin() const noexcept { #if _ITERATOR_DEBUG_LEVEL >= 1 From 7601af65851844a0bb313431c7c8497ce76f8cea Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 17:01:20 -0700 Subject: [PATCH 06/18] Add comment indicating non-WP fix --- stl/inc/xstring | 1 + 1 file changed, 1 insertion(+) diff --git a/stl/inc/xstring b/stl/inc/xstring index a8c26490404..cdb26da2764 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1310,6 +1310,7 @@ public: _Rng.operator basic_string_view<_Elem, _Traits>(); }) && ((!requires { + // per editorial or LWG issue not yet filed as of 2021-06-10 typename remove_reference_t<_Range>::traits_type; }) || same_as::traits_type, _Traits>) constexpr basic_string_view(_Range&& _Rng) noexcept( From 94f038226a7b66bc889138f3bc45480f0f9e15e0 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 17:05:53 -0700 Subject: [PATCH 07/18] Oops, forgot to remove the helper concept --- stl/inc/xstring | 9 --------- 1 file changed, 9 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index cdb26da2764..bbb3d39d695 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1238,15 +1238,6 @@ struct pointer_traits<_String_view_iterator<_Traits>> { }; #endif // _HAS_CXX20 -#if _HAS_CXX23 -// clang-format off -template -concept _Has_compatible_traits = !requires { - typename _Range::traits_type; -} || same_as::traits_type, _Traits>; -// clang-format on -#endif // _HAS_CXX23 - // CLASS TEMPLATE basic_string_view template From c2519ee34e68713658311fac0443b65770ae9412 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 18:24:41 -0700 Subject: [PATCH 08/18] Added deduction guides --- stl/inc/xstring | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stl/inc/xstring b/stl/inc/xstring index bbb3d39d695..7fa9c17c4a0 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1701,6 +1701,11 @@ private: template _Se> basic_string_view(_It, _Se) -> basic_string_view>; +#if _HAS_CXX23 +template <_RANGES contiguous_range _Range> +basic_string_view(_Range&&) -> basic_string_view<_RANGES range_value_t<_Range>>; +#endif // _HAS_CXX23 + namespace ranges { template inline constexpr bool enable_view> = true; From d93f9c373d1d70ac871f9017cdccbcdc253019e7 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 18:25:20 -0700 Subject: [PATCH 09/18] Reorder ranges dtor to be within existing __cpp_lib_concepts guard --- stl/inc/xstring | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 7fa9c17c4a0..cc0a446416c 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1289,9 +1289,8 @@ public: constexpr basic_string_view(_It _First, _Se _Last) noexcept(noexcept(_Last - _First)) // strengthened : _Mydata(_STD to_address(_First)), _Mysize(static_cast(_Last - _First)) {} // clang-format on -#endif // __cpp_lib_concepts -#if _HAS_CXX23 && defined(___cpp_lib_concepts) +#if _HAS_CXX23 // clang-format off template <_RANGES contiguous_range _Range> requires _RANGES sized_range<_Range> @@ -1308,7 +1307,8 @@ public: noexcept(_RANGES data(_Rng)) && noexcept(_RANGES size(_Rng))) // strengthened : _Mydata(_RANGES data(_Rng)), _Mysize(_RANGES size(_Rng)) {} // clang-format on -#endif // _HAS_CXX23 && defined(___cpp_lib_concepts) +#endif // _HAS_CXX23 +#endif // __cpp_lib_concepts _NODISCARD constexpr const_iterator begin() const noexcept { #if _ITERATOR_DEBUG_LEVEL >= 1 From 00d8cbbb518a6fa2fb97bfe2064ea0a649d7f2a5 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 18:34:13 -0700 Subject: [PATCH 10/18] Fixed traits constraint --- stl/inc/xstring | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index cc0a446416c..802e602737f 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1299,10 +1299,10 @@ public: && (!requires(remove_reference_t<_Range>& _Rng) { _Rng.operator basic_string_view<_Elem, _Traits>(); }) - && ((!requires { + && (!requires { // per editorial or LWG issue not yet filed as of 2021-06-10 typename remove_reference_t<_Range>::traits_type; - }) || same_as::traits_type, _Traits>) + } || same_as::traits_type, _Traits>) constexpr basic_string_view(_Range&& _Rng) noexcept( noexcept(_RANGES data(_Rng)) && noexcept(_RANGES size(_Rng))) // strengthened : _Mydata(_RANGES data(_Rng)), _Mysize(_RANGES size(_Rng)) {} From 5e695c4d8859b5b369bd49d32e431605d326b51c Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 18:34:28 -0700 Subject: [PATCH 11/18] Added test --- tests/std/tests/P0220R1_string_view/test.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/std/tests/P0220R1_string_view/test.cpp b/tests/std/tests/P0220R1_string_view/test.cpp index 3e611eef4d1..330d10fb2ab 100644 --- a/tests/std/tests/P0220R1_string_view/test.cpp +++ b/tests/std/tests/P0220R1_string_view/test.cpp @@ -1088,11 +1088,30 @@ static_assert(u8"abc"sv[1] == u8'b'); static_assert(noexcept(u8"abc"sv)); #endif // __cpp_char8_t +constexpr bool test_case_range_constructor() { +#if _HAS_CXX23 && defined(__cpp_lib_concepts) + const array expectedData{'n', 'o', ' ', 'n', 'u', 'l', 'l'}; + // Also tests the corresponding deduction guide: + same_as auto sv = basic_string_view(expectedData); + assert(sv.data() == expectedData.data()); + assert(sv.size() == 7); + assert(sv.length() == 7); + assert(!sv.empty()); + assert(sv[1] == 'o'); + assert(sv.at(1) == 'o'); + assert(sv.front() == 'n'); + assert(sv.back() == 'l'); +#endif // _HAS_CXX23 && defined(__cpp_lib_concepts) + + return true; +} + int main() { test_case_default_constructor(); test_case_ntcts_constructor(); test_case_buffer_constructor(); test_case_contiguous_constructor(); + test_case_range_constructor(); test_case_iterators>(); test_case_iterators>(); test_case_prefix>(); From 26631fbf6fa9a8fc4caecf2178b6f8c773252a5f Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 19:07:47 -0700 Subject: [PATCH 12/18] Add _HAS_CXX23 directly controls note --- stl/inc/yvals_core.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 3b2c62061be..828d5f58f83 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -255,6 +255,9 @@ // P1831R1 Deprecating volatile In The Standard Library // Other C++20 deprecation warnings +// _HAS_CXX23 directly controls: +// P1989R2 Range Constructor For string_view + // Parallel Algorithms Notes // C++ allows an implementation to implement parallel algorithms as calls to the serial algorithms. // This implementation parallelizes several common algorithm calls, but not all. From 98e2d8af49bcd0cdf325067e41b390071d9c0f4c Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 10 Jun 2021 19:41:28 -0700 Subject: [PATCH 13/18] Address review comments Co-authored-by: timsong-cpp --- stl/inc/xstring | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 802e602737f..b297dc96c9b 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1296,8 +1296,8 @@ public: requires _RANGES sized_range<_Range> && same_as<_RANGES range_value_t<_Range>, _Elem> && (!is_convertible_v<_Range, const _Elem*>) - && (!requires(remove_reference_t<_Range>& _Rng) { - _Rng.operator basic_string_view<_Elem, _Traits>(); + && (!requires(remove_cvref_t<_Range>& _Rng) { + _Rng.operator _STD basic_string_view<_Elem, _Traits>(); }) && (!requires { // per editorial or LWG issue not yet filed as of 2021-06-10 From 14a9d9135ce2174c3eb88f8f0a6fed1c5ace087e Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Fri, 11 Jun 2021 14:54:57 -0700 Subject: [PATCH 14/18] Added constexpr test and removed redundant lines --- tests/std/tests/P0220R1_string_view/test.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/std/tests/P0220R1_string_view/test.cpp b/tests/std/tests/P0220R1_string_view/test.cpp index 330d10fb2ab..eaef344e5d5 100644 --- a/tests/std/tests/P0220R1_string_view/test.cpp +++ b/tests/std/tests/P0220R1_string_view/test.cpp @@ -1095,17 +1095,13 @@ constexpr bool test_case_range_constructor() { same_as auto sv = basic_string_view(expectedData); assert(sv.data() == expectedData.data()); assert(sv.size() == 7); - assert(sv.length() == 7); - assert(!sv.empty()); - assert(sv[1] == 'o'); - assert(sv.at(1) == 'o'); - assert(sv.front() == 'n'); - assert(sv.back() == 'l'); #endif // _HAS_CXX23 && defined(__cpp_lib_concepts) return true; } +static_assert(test_case_range_constructor()); + int main() { test_case_default_constructor(); test_case_ntcts_constructor(); From 1e1be9e61ef7815add548008441601320c50bd90 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Fri, 11 Jun 2021 14:55:22 -0700 Subject: [PATCH 15/18] Removed unnecessary include and cast to `std::size_t` --- stl/inc/xstring | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 802e602737f..43764a19867 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -17,10 +17,6 @@ #include #endif // _HAS_CXX17 -#if _HAS_CXX23 -#include -#endif // _HAS_CXX23 - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -1305,7 +1301,7 @@ public: } || same_as::traits_type, _Traits>) constexpr basic_string_view(_Range&& _Rng) noexcept( noexcept(_RANGES data(_Rng)) && noexcept(_RANGES size(_Rng))) // strengthened - : _Mydata(_RANGES data(_Rng)), _Mysize(_RANGES size(_Rng)) {} + : _Mydata(_RANGES data(_Rng)), _Mysize(static_cast(_RANGES size(_Rng))) {} // clang-format on #endif // _HAS_CXX23 #endif // __cpp_lib_concepts From 10de48df5e33f0e5ebb8c9190e7550e38881b18e Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Fri, 11 Jun 2021 16:22:53 -0700 Subject: [PATCH 16/18] Update stl/inc/xstring Remove extraneous `std`-qualification on `size_t`. --- stl/inc/xstring | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 173e48b5088..9c12da9fee9 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1301,7 +1301,7 @@ public: } || same_as::traits_type, _Traits>) constexpr basic_string_view(_Range&& _Rng) noexcept( noexcept(_RANGES data(_Rng)) && noexcept(_RANGES size(_Rng))) // strengthened - : _Mydata(_RANGES data(_Rng)), _Mysize(static_cast(_RANGES size(_Rng))) {} + : _Mydata(_RANGES data(_Rng)), _Mysize(static_cast(_RANGES size(_Rng))) {} // clang-format on #endif // _HAS_CXX23 #endif // __cpp_lib_concepts From c588be2fc526a0cac43eeefefd9cc582f3788896 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 16 Jun 2021 18:27:45 -0700 Subject: [PATCH 17/18] Reorder test_case_range_constructor's definition and static_assert. --- tests/std/tests/P0220R1_string_view/test.cpp | 27 ++++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/std/tests/P0220R1_string_view/test.cpp b/tests/std/tests/P0220R1_string_view/test.cpp index eaef344e5d5..1de189d006a 100644 --- a/tests/std/tests/P0220R1_string_view/test.cpp +++ b/tests/std/tests/P0220R1_string_view/test.cpp @@ -322,6 +322,18 @@ constexpr bool test_case_contiguous_constructor() { return true; } +constexpr bool test_case_range_constructor() { +#if _HAS_CXX23 && defined(__cpp_lib_concepts) + const array expectedData{'n', 'o', ' ', 'n', 'u', 'l', 'l'}; + // Also tests the corresponding deduction guide: + same_as auto sv = basic_string_view(expectedData); + assert(sv.data() == expectedData.data()); + assert(sv.size() == 7); +#endif // _HAS_CXX23 && defined(__cpp_lib_concepts) + + return true; +} + template constexpr bool test_case_iterators() { using iterator = typename basic_string_view::iterator; @@ -1048,6 +1060,7 @@ static_assert(test_case_default_constructor()); static_assert(test_case_ntcts_constructor()); static_assert(test_case_buffer_constructor()); static_assert(test_case_contiguous_constructor()); +static_assert(test_case_range_constructor()); #if defined(__clang__) || defined(__EDG__) // TRANSITION, VSO-284079 "C1XX's C++14 constexpr emits bogus warnings C4146, // C4308, C4307 for basic_string_view::iterator" static_assert(test_case_iterators()); @@ -1088,20 +1101,6 @@ static_assert(u8"abc"sv[1] == u8'b'); static_assert(noexcept(u8"abc"sv)); #endif // __cpp_char8_t -constexpr bool test_case_range_constructor() { -#if _HAS_CXX23 && defined(__cpp_lib_concepts) - const array expectedData{'n', 'o', ' ', 'n', 'u', 'l', 'l'}; - // Also tests the corresponding deduction guide: - same_as auto sv = basic_string_view(expectedData); - assert(sv.data() == expectedData.data()); - assert(sv.size() == 7); -#endif // _HAS_CXX23 && defined(__cpp_lib_concepts) - - return true; -} - -static_assert(test_case_range_constructor()); - int main() { test_case_default_constructor(); test_case_ntcts_constructor(); From 1f1a77afa172ea91491fee624cca05dc68fc4592 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 16 Jun 2021 19:28:28 -0700 Subject: [PATCH 18/18] Add constraint tests. --- tests/std/tests/P0220R1_string_view/test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/std/tests/P0220R1_string_view/test.cpp b/tests/std/tests/P0220R1_string_view/test.cpp index 1de189d006a..d1b4f1d6dc1 100644 --- a/tests/std/tests/P0220R1_string_view/test.cpp +++ b/tests/std/tests/P0220R1_string_view/test.cpp @@ -3,11 +3,14 @@ #include #include +#include #include #include #include #include #include +#include +#include #include @@ -329,6 +332,19 @@ constexpr bool test_case_range_constructor() { same_as auto sv = basic_string_view(expectedData); assert(sv.data() == expectedData.data()); assert(sv.size() == 7); + + // Also tests some of the constraints: + static_assert(is_constructible_v>); + static_assert(is_convertible_v, string_view>); + + static_assert(!is_constructible_v>); // not contiguous + static_assert(!is_convertible_v, string_view>); + + static_assert(!is_constructible_v>); // different elements + static_assert(!is_convertible_v, string_view>); + + static_assert(!is_constructible_v>); // different traits + static_assert(!is_convertible_v, string_view>); #endif // _HAS_CXX23 && defined(__cpp_lib_concepts) return true;