summaryrefslogtreecommitdiff
path: root/libcxx
diff options
context:
space:
mode:
authorzijunzhao <zijunzhao@google.com>2023-05-16 22:49:48 +0000
committerzijunzhao <zijunzhao@google.com>2023-05-17 16:14:15 +0000
commitf9f1f9c2a533d5caa3ddf813ebbd16fe3a13fce7 (patch)
treea6b487b8383277d2c318a4d9d04f7dd486704f37 /libcxx
parent40e902c496040086f43200c8f59e0319d334770a (diff)
downloadllvm-f9f1f9c2a533d5caa3ddf813ebbd16fe3a13fce7.tar.gz
[libc++] Improve ranges::starts_with
Fix some nits in ranges::starts_with
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.starts_with/ranges.starts_with.pass.cpp44
1 files changed, 20 insertions, 24 deletions
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<UncheckedRange<int*>, ForwardRangeNotIncrementable>
static_assert(!HasStartsWithR<UncheckedRange<int*>, ForwardRangeNotSentinelSemiregular>);
static_assert(!HasStartsWithR<UncheckedRange<int*>, ForwardRangeNotSentinelEqualityComparableWith>);
+// clang-format off
template <class Iter1, class Sent1 = Iter1, class Iter2, class Sent2 = Iter2>
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<int*>{}, []<class I2>() {
- types::for_each(types::forward_iterator_list<int*>{}, []<class I1>() {
- test_iterators<I1, I1, I2, I2>();
- test_iterators<I1, sized_sentinel<I1>, I2, I2>();
- test_iterators<I1, I1, I2, sized_sentinel<I2>>();
- test_iterators<I1, sized_sentinel<I1>, I2, sized_sentinel<I2>>();
+ types::for_each(types::cpp20_input_iterator_list<int*>{}, []<class Iter2>() {
+ types::for_each(types::cpp20_input_iterator_list<int*>{}, []<class Iter1>() {
+ if constexpr (std::forward_iterator<Iter1> && std::forward_iterator<Iter2>)
+ test_iterators<Iter1, Iter1, Iter2, Iter2>();
+ if constexpr (std::forward_iterator<Iter2>)
+ test_iterators<Iter1, sized_sentinel<Iter1>, Iter2, Iter2>();
+ if constexpr (std::forward_iterator<Iter1>)
+ test_iterators<Iter1, Iter1, Iter2, sized_sentinel<Iter2>>();
+ test_iterators<Iter1, sized_sentinel<Iter1>, Iter2, sized_sentinel<Iter2>>();
});
});
- // 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;
}