Skip to content

Commit 95e4fed

Browse files
committed
Add a test for ranges::contains
1 parent 7e75b07 commit 95e4fed

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Copyright (C) 2026 UXL Foundation Contributors
5+
//
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "std_ranges_test.h"
11+
12+
#if _ENABLE_STD_RANGES_TESTING
13+
#if __cpp_lib_ranges_contains >= 202207L
14+
auto contains_checker = TEST_PREPARE_CALLABLE(std::ranges::contains);
15+
#else
16+
struct {
17+
template<std::ranges::input_range R, typename V, typename Proj = std::identity>
18+
bool operator()(R&& r, V value, Proj proj = {})
19+
{
20+
auto last = std::ranges::end(r);
21+
return std::ranges::find(std::ranges::begin(r), last, value, proj) != last;
22+
}
23+
} contains_checker;
24+
#endif
25+
#endif
26+
27+
std::int32_t
28+
main()
29+
{
30+
#if _ENABLE_STD_RANGES_TESTING
31+
using namespace test_std_ranges;
32+
namespace dpl_ranges = oneapi::dpl::ranges;
33+
34+
// expected to be found
35+
test_range_algo<0>{big_sz}(dpl_ranges::contains, contains_checker, small_size - 19);
36+
test_range_algo<1>{}(dpl_ranges::contains, contains_checker, proj(small_size/2 + 28), proj);
37+
test_range_algo<2, P2>{}(dpl_ranges::contains, contains_checker, 137, &P2::x);
38+
39+
// expected to be absent
40+
test_range_algo<3, P2>{}(dpl_ranges::contains, contains_checker, -27, &P2::proj);
41+
test_range_algo<4>{big_sz}(dpl_ranges::contains, contains_checker, -43);
42+
#endif //_ENABLE_STD_RANGES_TESTING
43+
44+
return TestUtils::done(_ENABLE_STD_RANGES_TESTING);
45+
}

0 commit comments

Comments
 (0)