From f9f1f9c2a533d5caa3ddf813ebbd16fe3a13fce7 Mon Sep 17 00:00:00 2001 From: zijunzhao Date: Tue, 16 May 2023 22:49:48 +0000 Subject: [libc++] Improve ranges::starts_with Fix some nits in ranges::starts_with --- .../alg.starts_with/ranges.starts_with.pass.cpp | 44 ++++++++++------------ 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'libcxx') diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.starts_with/ranges.starts_with.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.starts_with/ranges.starts_with.pass.cpp index 78565b354c04..85c6bf96b2aa 100644 --- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.starts_with/ranges.starts_with.pass.cpp +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.starts_with/ranges.starts_with.pass.cpp @@ -58,10 +58,10 @@ static_assert(HasStartsWithR, ForwardRangeNotIncrementable> static_assert(!HasStartsWithR, ForwardRangeNotSentinelSemiregular>); static_assert(!HasStartsWithR, ForwardRangeNotSentinelEqualityComparableWith>); +// clang-format off template constexpr void test_iterators() { - // simple tests - { + { // simple tests { int a[] = {1, 2, 3, 4, 5, 6}; int p[] = {1, 2}; @@ -79,8 +79,7 @@ constexpr void test_iterators() { } } - // prefix doesn't match - { + { // prefix doesn't match { int a[] = {1, 2, 3, 4, 5, 6}; int p[] = {4, 5, 6}; @@ -98,8 +97,7 @@ constexpr void test_iterators() { } } - // range and prefix are identical - { + { // range and prefix are identical { int a[] = {1, 2, 3, 4, 5, 6}; int p[] = {1, 2, 3, 4, 5, 6}; @@ -117,8 +115,7 @@ constexpr void test_iterators() { } } - // prefix is longer than range - { + { // prefix is longer than range { int a[] = {1, 2, 3, 4, 5, 6}; int p[] = {1, 2, 3, 4, 5, 6, 7, 8}; @@ -136,8 +133,7 @@ constexpr void test_iterators() { } } - // prefix has zero length - { + { // prefix has zero length { int a[] = {1, 2, 3, 4, 5, 6}; int p[] = {}; @@ -155,8 +151,7 @@ constexpr void test_iterators() { } } - // range has zero length - { + { // range has zero length { int a[] = {}; int p[] = {1, 2, 3, 4, 5, 6, 7, 8}; @@ -174,8 +169,7 @@ constexpr void test_iterators() { } } - // check that the predicate is used - { + { // check that the predicate is used { int a[] = {11, 8, 3, 4, 0, 6}; int p[] = {1, 12}; @@ -193,8 +187,7 @@ constexpr void test_iterators() { } } - // check that the projections are used - { + { // check that the projections are used { int a[] = {1, 3, 5, 1, 5, 6}; int p[] = {2, 3, 4}; @@ -221,17 +214,19 @@ constexpr void test_iterators() { } constexpr bool test() { - types::for_each(types::forward_iterator_list{}, []() { - types::for_each(types::forward_iterator_list{}, []() { - test_iterators(); - test_iterators, I2, I2>(); - test_iterators>(); - test_iterators, I2, sized_sentinel>(); + types::for_each(types::cpp20_input_iterator_list{}, []() { + types::for_each(types::cpp20_input_iterator_list{}, []() { + if constexpr (std::forward_iterator && std::forward_iterator) + test_iterators(); + if constexpr (std::forward_iterator) + test_iterators, Iter2, Iter2>(); + if constexpr (std::forward_iterator) + test_iterators>(); + test_iterators, Iter2, sized_sentinel>(); }); }); - // check that std::invoke is used - { + { // check that std::invoke is used struct S { int i; @@ -259,5 +254,6 @@ constexpr bool test() { int main(int, char**) { test(); static_assert(test()); + return 0; } -- cgit v1.2.1