[Lldb-commits] [lldb] [libc++] Implement ranges::contains_subrange (PR #66963)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 26 17:07:41 PDT 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 2f2319cf2406d9830a331cbf015881c55ae78806 5f33fa63e76b5d0c066773113447749c3428aa99 -- libcxx/include/__algorithm/ranges_contains_subrange.h libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
index fd4d858b255d..e9c300e5bb20 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
@@ -51,7 +51,8 @@ static_assert(HasContainsSubrangeSubrangeIt<int*, int*>);
template <class Range1, class Range2 = UncheckedRange<int*>>
concept HasContainsSubrangeR = requires(Range1&& range1, Range2&& range2) {
- std::ranges::contains_subrange(std::forward<Range1>(range1), std::forward<Range2>(range2)); };
+ std::ranges::contains_subrange(std::forward<Range1>(range1), std::forward<Range2>(range2));
+};
static_assert(HasContainsSubrangeR<UncheckedRange<int*>>);
static_assert(HasContainsSubrangeR<ForwardRangeNotDerivedFrom>);
@@ -68,27 +69,26 @@ static std::vector<int> comparable_data;
template <class Iter1, class Sent1 = Iter1, class Iter2, class Sent2 = Iter2>
constexpr void test_iterators() {
- { // simple tests
- int a[] = {1, 2, 3, 4, 5, 6};
- int p[] = {3, 4, 5};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+ { // simple tests
+ int a[] = {1, 2, 3, 4, 5, 6};
+ int p[] = {3, 4, 5};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
{
[[maybe_unused]] std::same_as<bool> decltype(auto) ret =
- std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
+ std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
assert(ret);
}
{
- [[maybe_unused]] std::same_as<bool> decltype(auto) ret =
- std::ranges::contains_subrange(whole, subrange);
+ [[maybe_unused]] std::same_as<bool> decltype(auto) ret = std::ranges::contains_subrange(whole, subrange);
assert(ret);
}
}
{ // no match
- int a[] = {1, 2, 3, 4, 5, 6};
- int p[] = {3, 4, 2};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+ int a[] = {1, 2, 3, 4, 5, 6};
+ int p[] = {3, 4, 2};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
{
bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
@@ -101,9 +101,9 @@ constexpr void test_iterators() {
}
{ // range consists of just one element
- int a[] = {3};
- int p[] = {3, 4, 2};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 1)));
+ int a[] = {3};
+ int p[] = {3, 4, 2};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 1)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
{
bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
@@ -116,9 +116,9 @@ constexpr void test_iterators() {
}
{ // subrange consists of just one element
- int a[] = {23, 1, 20, 3, 54, 2};
- int p[] = {3};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+ int a[] = {23, 1, 20, 3, 54, 2};
+ int p[] = {3};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 1)));
{
bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
@@ -131,9 +131,9 @@ constexpr void test_iterators() {
}
{ // range has zero length
- int a[] = {};
- int p[] = {3, 4, 2};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
+ int a[] = {};
+ int p[] = {3, 4, 2};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
{
bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
@@ -146,9 +146,9 @@ constexpr void test_iterators() {
}
{ // subrange has zero length
- int a[] = {3, 4, 2};
- int p[] = {};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
+ int a[] = {3, 4, 2};
+ int p[] = {};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p)));
{
bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
@@ -161,9 +161,9 @@ constexpr void test_iterators() {
}
{ // range and subrange are identical
- int a[] = {3, 4, 11, 32, 54, 2};
- int p[] = {3, 4, 11, 32, 54, 2};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+ int a[] = {3, 4, 11, 32, 54, 2};
+ int p[] = {3, 4, 11, 32, 54, 2};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 6)));
{
bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
@@ -176,9 +176,9 @@ constexpr void test_iterators() {
}
{ // subrange is longer than range
- int a[] = {3, 4, 2};
- int p[] = {23, 3, 4, 2, 11, 32, 54, 2};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
+ int a[] = {3, 4, 2};
+ int p[] = {23, 3, 4, 2, 11, 32, 54, 2};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 8)));
{
bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
@@ -191,9 +191,9 @@ constexpr void test_iterators() {
}
{ // subrange is subsequence
- int a[] = {23, 1, 0, 54, 2};
- int p[] = {1, 0, 2};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 5)));
+ int a[] = {23, 1, 0, 54, 2};
+ int p[] = {1, 0, 2};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 5)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
{
bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
@@ -206,9 +206,9 @@ constexpr void test_iterators() {
}
{ // repeated subrange
- int a[] = {23, 1, 0, 2, 54, 1, 0, 2, 23, 33};
- int p[] = {1, 0, 2};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 10)));
+ int a[] = {23, 1, 0, 2, 54, 1, 0, 2, 23, 33};
+ int p[] = {1, 0, 2};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 10)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
{
bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end());
@@ -221,10 +221,10 @@ constexpr void test_iterators() {
}
{ // check that the predicate is used
- int a[] = {23, 81, 61, 0, 42, 25, 1, 2, 1, 29, 2};
- int p[] = {-1, -2, -1};
- auto pred = [](int l, int r) { return l * -1 == r; };
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 11)));
+ int a[] = {23, 81, 61, 0, 42, 25, 1, 2, 1, 29, 2};
+ int p[] = {-1, -2, -1};
+ auto pred = [](int l, int r) { return l * -1 == r; };
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 11)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
{
bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end(), pred);
@@ -237,40 +237,44 @@ constexpr void test_iterators() {
}
{ // check that the projections are used
- int a[] = {1, 3, 15, 1, 2, 1, 8};
- int p[] = {2, 1, 2};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 7)));
- auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
+ int a[] = {1, 3, 15, 1, 2, 1, 8};
+ int p[] = {2, 1, 2};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 7)));
+ auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
{
- bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end(), {},
- [](int i) { return i - 3; },
- [](int i) { return i * -1; });
+ bool ret = std::ranges::contains_subrange(
+ whole.begin(),
+ whole.end(),
+ subrange.begin(),
+ subrange.end(),
+ {},
+ [](int i) { return i - 3; },
+ [](int i) { return i * -1; });
assert(ret);
}
{
- bool ret = std::ranges::contains_subrange(whole, subrange, {},
- [](int i) { return i - 3; },
- [](int i) { return i * -1; });
+ bool ret = std::ranges::contains_subrange(
+ whole, subrange, {}, [](int i) { return i - 3; }, [](int i) { return i * -1; });
assert(ret);
}
}
{ // check the nodiscard extension
- // use #pragma around to suppress error: ignoring return value of function
- // declared with 'nodiscard' attribute [-Werror,-Wunused-result]
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wunused-result"
- int a[] = {1, 9, 0, 13, 25};
- int p[] = {1, 9, 0};
- auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 5)));
+// use #pragma around to suppress error: ignoring return value of function
+// declared with 'nodiscard' attribute [-Werror,-Wunused-result]
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-result"
+ int a[] = {1, 9, 0, 13, 25};
+ int p[] = {1, 9, 0};
+ auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 5)));
auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
std::ranges::contains_subrange(whole, subrange);
- #pragma clang diagnostic pop
+#pragma clang diagnostic pop
}
}
constexpr bool test() {
- types::for_each(types::cpp20_input_iterator_list<int*>{}, []<class Iter2>() {
+ 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>();
``````````
</details>
https://github.com/llvm/llvm-project/pull/66963
More information about the lldb-commits
mailing list