[Lldb-commits] [libunwind] [llvm] [clang-tools-extra] [clang] [mlir] [libc] [lldb] [libcxx] [lld] [compiler-rt] [libcxxabi] [flang] [libc++] Implement ranges::contains (PR #65148)
https://github.com/var-const approved this pull request. Thanks a lot for working on this! LGTM with a couple simple comments. https://github.com/llvm/llvm-project/pull/65148 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [mlir] [flang] [llvm] [libc] [libunwind] [lldb] [libcxxabi] [clang] [libcxx] [lld] [clang-tools-extra] [compiler-rt] [libc++] Implement ranges::contains (PR #65148)
@@ -0,0 +1,49 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include +#include +#include + +#include "test_iterators.h" var-const wrote: Nit: please move the `` include above so that it goes right after ``. https://github.com/llvm/llvm-project/pull/65148 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [libunwind] [llvm] [libcxxabi] [compiler-rt] [clang-tools-extra] [lld] [libcxx] [flang] [lldb] [clang] [libc] [mlir] [libc++] Implement ranges::contains (PR #65148)
https://github.com/var-const edited https://github.com/llvm/llvm-project/pull/65148 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [libcxxabi] [libc] [mlir] [clang-tools-extra] [lld] [llvm] [libcxx] [libunwind] [flang] [clang] [compiler-rt] [lldb] [libc++] Implement ranges::contains (PR #65148)
@@ -0,0 +1,49 @@ +//===--===// var-const wrote: Thanks a lot for adding the benchmark! Can you please post the results you're getting in the patch/commit description for potential future reference? https://github.com/llvm/llvm-project/pull/65148 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [compiler-rt] [lldb] [clang] [clang-tools-extra] [lld] [mlir] [libcxx] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)
https://github.com/var-const unassigned https://github.com/llvm/llvm-project/pull/66963 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lld] [llvm] [mlir] [compiler-rt] [clang] [libcxx] [clang-tools-extra] [lldb] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)
https://github.com/var-const unassigned https://github.com/llvm/llvm-project/pull/66963 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [flang] [mlir] [compiler-rt] [lldb] [clang] [llvm] [lld] [clang-tools-extra] [libunwind] [libc] [openmp] [libcxxabi] [libcxx] [libc++] Implement ranges::contains (PR #65148)
@@ -0,0 +1,61 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H +#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H + +#include <__algorithm/ranges_find.h> +#include <__config> +#include <__functional/identity.h> +#include <__functional/ranges_operations.h> +#include <__functional/reference_wrapper.h> +#include <__iterator/concepts.h> +#include <__iterator/indirectly_comparable.h> +#include <__iterator/projected.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace ranges { +namespace __contains { +struct __fn { + template _Sent, class _Type, class _Proj = identity> +requires indirect_binary_predicate, const _Type*> + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool + operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const { +return ranges::find(std::move(__first), std::move(__last), __value, std::ref(__proj)) != __last; var-const wrote: Thanks for catching this! https://github.com/llvm/llvm-project/pull/65148 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [openmp] [clang-tools-extra] [clang] [libunwind] [libc] [mlir] [llvm] [lld] [libcxx] [lldb] [compiler-rt] [libcxxabi] [flang] [libc++] Implement ranges::contains (PR #65148)
@@ -0,0 +1,195 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 + +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template +// requires indirect_binary_predicate, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include +#include +#include +#include + +#include "almost_satisfies_types.h" +#include "boolean_testable.h" +#include "test_iterators.h" + +struct NotEqualityComparable {}; + +template +concept HasContainsIt = requires(Iter iter, Sent sent) { std::ranges::contains(iter, sent, *iter); }; + +static_assert(HasContainsIt); +static_assert(HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt, SentinelForNotSemiregular>); +static_assert(!HasContainsIt, InputRangeNotSentinelEqualityComparableWith>); +static_assert(!HasContainsIt, sentinel_wrapper>>); + +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); + +template +concept HasContainsR = requires(Range&& range) { std::ranges::contains(std::forward(range), ValT{}); }; + +static_assert(!HasContainsR); +static_assert(HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); + +template +constexpr void test_iterators() { + using ValueT = std::iter_value_t; + { // simple tests +ValueT a[] = {1, 2, 3, 4, 5, 6}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 6))); +{ + std::same_as decltype(auto) ret = std::ranges::contains(whole.begin(), whole.end(), 3); + assert(ret); +} +{ + std::same_as decltype(auto) ret = std::ranges::contains(whole, 3); + assert(ret); +} + } + + { // check that a range with a single element works +ValueT a[] = {32}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 1))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // check that an empty range works +ValueT a[] = {}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 1); + assert(!ret); +} +{ + bool ret = std::ranges::contains(whole, 1); + assert(!ret); +} + } + + { // check that the first element matches +ValueT a[] = {32, 3, 2, 1, 0, 23, 21, 9, 40, 100}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 10))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // check that the last element matches +ValueT a[] = {3, 22, 1, 43, 99, 0, 56, 100, 32}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 9))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // no match +ValueT a[] = {13, 1, 21, 4, 5}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 5))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 10); + assert(!ret); +} +{ + bool ret = std::ranges::contains(whole, 10); + assert(!ret); +} + } + + { // check that the projections are used +int a[] = {1, 9, 0, 13, 25}; +{ + bool ret = std::ranges::contains(a, a + 5, -13, [&](int i) { return i * -1; }); + assert(ret); +} +{ + auto range = std::ranges::subrange(a, a + 5); + bool ret = std::ranges::contains(range, -13, [&](int i) { return i * -1; }); + assert(ret); +} + } +} + +constexpr bool test() { + types::for_each(types::type_list{}, [] { +types::for_each(types::cpp20_input_iterator_list{}, [] { + if constexpr (std::forward_iterator) +test_iterators(); + test_iterators>(); + test_iterators>(); +}); + }); + + { // count invocations of the projection var-const wrote: Can you provide some examples? https://github.com/llvm/llvm-project/pul
[Lldb-commits] [flang] [mlir] [compiler-rt] [lldb] [clang] [llvm] [lld] [clang-tools-extra] [libunwind] [libc] [openmp] [libcxxabi] [libcxx] [libc++] Implement ranges::contains (PR #65148)
@@ -34,6 +35,10 @@ struct __identity { template <> struct __is_identity<__identity> : true_type {}; +template <> var-const wrote: Can you elaborate on your concerns here? https://github.com/llvm/llvm-project/pull/65148 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [lldb] [mlir] [clang-tools-extra] [libcxx] [compiler-rt] [lld] [clang] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,303 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 +// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=200 + +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template +// requires indirect_binary_predicate, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include +#include +#include +#include +#include + +#include "almost_satisfies_types.h" +#include "boolean_testable.h" +#include "test_iterators.h" + +struct NotEqualityComparable {}; + +template +concept HasContainsSubrangeIt = requires(Iter1 first1, Sent1 last1, Iter2 first2, Sent2 last2) { + std::ranges::contains_subrange(first1, last1, first2, last2); +}; + +static_assert(HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); // not indirectly comparable +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); + +template > +concept HasContainsSubrangeR = requires(Range1&& range1, Range2&& range2) { + std::ranges::contains_subrange(std::forward(range1), std::forward(range2)); }; + +static_assert(HasContainsSubrangeR>); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR, UncheckedRange>); // not indirectly comparable +static_assert(!HasContainsSubrangeR, ForwardRangeNotDerivedFrom>); +static_assert(!HasContainsSubrangeR, ForwardRangeNotIncrementable>); +static_assert(!HasContainsSubrangeR, ForwardRangeNotSentinelSemiregular>); +static_assert(!HasContainsSubrangeR, ForwardRangeNotSentinelEqualityComparableWith>); + +template +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))); +auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3))); +{ + [[maybe_unused]] std::same_as decltype(auto) ret = + std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end()); + assert(ret); +} +{ + [[maybe_unused]] std::same_as 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))); +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()); + assert(!ret); +} +{ + bool ret = std::ranges::contains_subrange(whole, subrange); + assert(!ret); +} + } + + { // 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))); +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()); + assert(!ret); +} +{ + bool ret = std::ranges::contains_subrange(whole, subrange); + assert(!ret); +} + } + + { // 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))); +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()); + assert(ret); +} +{ + bool ret = std::ranges::contains_subrange(whole, subrange); + assert(ret); +} + } + + { // range has zero length +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.e
[Lldb-commits] [lldb] [libc++] Implement ranges::contains (PR #65148)
@@ -0,0 +1,252 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 + +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template +// requires indirect_binary_predicate, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include +#include +#include +#include +#include + +#include "almost_satisfies_types.h" +#include "boolean_testable.h" +#include "test_iterators.h" + +struct NotEqualityComparable {}; + +template +concept HasContainsIt = requires(Iter iter, Sent sent) { std::ranges::contains(iter, sent, *iter); }; + +static_assert(HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt, SentinelForNotSemiregular>); +static_assert(!HasContainsIt, InputRangeNotSentinelEqualityComparableWith>); +static_assert(!HasContainsIt, sentinel_wrapper>>); + +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(HasContainsIt); + +template +concept HasContainsR = requires(Range&& range) { std::ranges::contains(std::forward(range), ValT{}); }; + +static_assert(!HasContainsR); +static_assert(HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); + +static std::vector comparable_data; + +template +constexpr void test_iterators() { + using ValueT = std::iter_value_t; + { // simple tests +ValueT a[] = {1, 2, 3, 4, 5, 6}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 6))); +{ + [[maybe_unused]] std::same_as decltype(auto) ret = var-const wrote: We're using `ret` in the assert below, so I think this `maybe_unused` shouldn't be necessary. https://github.com/llvm/llvm-project/pull/65148 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [libc++] Implement ranges::contains (PR #65148)
@@ -0,0 +1,252 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 + +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template +// requires indirect_binary_predicate, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include +#include +#include +#include +#include + +#include "almost_satisfies_types.h" +#include "boolean_testable.h" +#include "test_iterators.h" + +struct NotEqualityComparable {}; + +template +concept HasContainsIt = requires(Iter iter, Sent sent) { std::ranges::contains(iter, sent, *iter); }; + +static_assert(HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt, SentinelForNotSemiregular>); +static_assert(!HasContainsIt, InputRangeNotSentinelEqualityComparableWith>); +static_assert(!HasContainsIt, sentinel_wrapper>>); + +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(HasContainsIt); + +template +concept HasContainsR = requires(Range&& range) { std::ranges::contains(std::forward(range), ValT{}); }; + +static_assert(!HasContainsR); +static_assert(HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); + +static std::vector comparable_data; + +template +constexpr void test_iterators() { + using ValueT = std::iter_value_t; + { // simple tests +ValueT a[] = {1, 2, 3, 4, 5, 6}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 6))); +{ + [[maybe_unused]] std::same_as decltype(auto) ret = +std::ranges::contains(whole.begin(), whole.end(), 3); + assert(ret); +} +{ + [[maybe_unused]] std::same_as decltype(auto) ret = +std::ranges::contains(whole, 3); + assert(ret); +} + } + + { // check that a range with a single element works +ValueT a[] = {32}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 1))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // check that an empty range works +ValueT a[] = {}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 1); + assert(!ret); +} +{ + bool ret = std::ranges::contains(whole, 1); + assert(!ret); +} + } + + { // check that the first element matches +ValueT a[] = {32, 3, 2, 1, 0, 23, 21, 9, 40, 100}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 10))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // check that the last element matches +ValueT a[] = {3, 22, 1, 43, 99, 0, 56, 100, 32}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 9))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // no match +ValueT a[] = {13, 1, 21, 4, 5}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 5))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 10); + assert(!ret); +} +{ + bool ret = std::ranges::contains(whole, 10); + assert(!ret); +} + } + + { // check that the projections are used +int a[] = {1, 9, 0, 13, 25}; +{ + bool ret = std::ranges::contains(a, a + 5, -13, [&](int i) { return i * -1; }); + assert(ret); +} +{ + auto range = std::ranges::subrange(a, a + 5); + bool ret = std::ranges::contains(range, -13, [&](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" +ValueT a[] = {1, 9, 0, 13, 25}; +auto w
[Lldb-commits] [lldb] [libc++] Implement ranges::contains (PR #65148)
@@ -0,0 +1,252 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 + +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template +// requires indirect_binary_predicate, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include +#include +#include +#include +#include + +#include "almost_satisfies_types.h" +#include "boolean_testable.h" +#include "test_iterators.h" + +struct NotEqualityComparable {}; + +template +concept HasContainsIt = requires(Iter iter, Sent sent) { std::ranges::contains(iter, sent, *iter); }; + +static_assert(HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt, SentinelForNotSemiregular>); +static_assert(!HasContainsIt, InputRangeNotSentinelEqualityComparableWith>); +static_assert(!HasContainsIt, sentinel_wrapper>>); + +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(HasContainsIt); + +template +concept HasContainsR = requires(Range&& range) { std::ranges::contains(std::forward(range), ValT{}); }; + +static_assert(!HasContainsR); +static_assert(HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); + +static std::vector comparable_data; + +template +constexpr void test_iterators() { + using ValueT = std::iter_value_t; + { // simple tests +ValueT a[] = {1, 2, 3, 4, 5, 6}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 6))); +{ + [[maybe_unused]] std::same_as decltype(auto) ret = +std::ranges::contains(whole.begin(), whole.end(), 3); + assert(ret); +} +{ + [[maybe_unused]] std::same_as decltype(auto) ret = +std::ranges::contains(whole, 3); + assert(ret); +} + } + + { // check that a range with a single element works +ValueT a[] = {32}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 1))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // check that an empty range works +ValueT a[] = {}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 1); + assert(!ret); +} +{ + bool ret = std::ranges::contains(whole, 1); + assert(!ret); +} + } + + { // check that the first element matches +ValueT a[] = {32, 3, 2, 1, 0, 23, 21, 9, 40, 100}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 10))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // check that the last element matches +ValueT a[] = {3, 22, 1, 43, 99, 0, 56, 100, 32}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 9))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // no match +ValueT a[] = {13, 1, 21, 4, 5}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 5))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 10); + assert(!ret); +} +{ + bool ret = std::ranges::contains(whole, 10); + assert(!ret); +} + } + + { // check that the projections are used +int a[] = {1, 9, 0, 13, 25}; +{ + bool ret = std::ranges::contains(a, a + 5, -13, [&](int i) { return i * -1; }); + assert(ret); +} +{ + auto range = std::ranges::subrange(a, a + 5); + bool ret = std::ranges::contains(range, -13, [&](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" +ValueT a[] = {1, 9, 0, 13, 25}; +auto w
[Lldb-commits] [lldb] [libc++] Implement ranges::contains (PR #65148)
@@ -0,0 +1,252 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 + +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template +// requires indirect_binary_predicate, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include +#include +#include +#include +#include + +#include "almost_satisfies_types.h" +#include "boolean_testable.h" +#include "test_iterators.h" + +struct NotEqualityComparable {}; + +template +concept HasContainsIt = requires(Iter iter, Sent sent) { std::ranges::contains(iter, sent, *iter); }; + +static_assert(HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt, SentinelForNotSemiregular>); +static_assert(!HasContainsIt, InputRangeNotSentinelEqualityComparableWith>); +static_assert(!HasContainsIt, sentinel_wrapper>>); + +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(HasContainsIt); + +template +concept HasContainsR = requires(Range&& range) { std::ranges::contains(std::forward(range), ValT{}); }; + +static_assert(!HasContainsR); +static_assert(HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); + +static std::vector comparable_data; + +template +constexpr void test_iterators() { + using ValueT = std::iter_value_t; + { // simple tests +ValueT a[] = {1, 2, 3, 4, 5, 6}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 6))); +{ + [[maybe_unused]] std::same_as decltype(auto) ret = +std::ranges::contains(whole.begin(), whole.end(), 3); + assert(ret); +} +{ + [[maybe_unused]] std::same_as decltype(auto) ret = +std::ranges::contains(whole, 3); + assert(ret); +} + } + + { // check that a range with a single element works +ValueT a[] = {32}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 1))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // check that an empty range works +ValueT a[] = {}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 1); + assert(!ret); +} +{ + bool ret = std::ranges::contains(whole, 1); + assert(!ret); +} + } + + { // check that the first element matches +ValueT a[] = {32, 3, 2, 1, 0, 23, 21, 9, 40, 100}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 10))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // check that the last element matches +ValueT a[] = {3, 22, 1, 43, 99, 0, 56, 100, 32}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 9))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 32); + assert(ret); +} +{ + bool ret = std::ranges::contains(whole, 32); + assert(ret); +} + } + + { // no match +ValueT a[] = {13, 1, 21, 4, 5}; +auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a + 5))); +{ + bool ret = std::ranges::contains(whole.begin(), whole.end(), 10); + assert(!ret); +} +{ + bool ret = std::ranges::contains(whole, 10); + assert(!ret); +} + } + + { // check that the projections are used +int a[] = {1, 9, 0, 13, 25}; +{ + bool ret = std::ranges::contains(a, a + 5, -13, [&](int i) { return i * -1; }); + assert(ret); +} +{ + auto range = std::ranges::subrange(a, a + 5); + bool ret = std::ranges::contains(range, -13, [&](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" +ValueT a[] = {1, 9, 0, 13, 25}; +auto w
[Lldb-commits] [lldb] [libc++] Implement ranges::contains (PR #65148)
https://github.com/var-const unassigned https://github.com/llvm/llvm-project/pull/65148 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [libc++] Implement ranges::contains (PR #65148)
@@ -0,0 +1,190 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template +// requires indirect_binary_predicate, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include +#include +#include +#include +#include + +#include "almost_satisfies_types.h" +#include "boolean_testable.h" +#include "test_iterators.h" + +struct NotEqualityComparable {}; + +template +concept HasContainsIt = requires(Iter iter, Sent sent) { std::ranges::contains(iter, sent, *iter); }; + +static_assert(HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); +static_assert(!HasContainsIt, SentinelForNotSemiregular>); +static_assert(!HasContainsIt, InputRangeNotSentinelEqualityComparableWith>); + +static_assert(!HasContainsIt); +static_assert(!HasContainsIt); + +template +concept HasContainsR = requires(Range range) { std::ranges::contains(range, ValT{}); }; + +static_assert(HasContainsR, int>); +static_assert(!HasContainsR); +static_assert(!HasContainsR, NotEqualityComparable>); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); +static_assert(!HasContainsR); + +static std::vector comparable_data; + +// clang-format off +template +constexpr void test_iterators() { + using ValueT = std::iter_value_t; + { // simple tests +{ + ValueT a[] = {1, 2, 3, 4, 5, 6}; + std::same_as auto ret = +std::ranges::contains(Iter(a), Sent(Iter(a + 6)), 3); + assert(ret); +} +{ + ValueT a[] = {1, 2, 3, 4, 5, 6}; + auto range = std::ranges::subrange(Iter(a), Sent(Iter(a + 6))); + std::same_as decltype(auto) ret = +std::ranges::contains(range, 3); + assert(ret); +} + } + + { // check that an empty range works +{ + ValueT a[] = {}; + auto ret = std::ranges::contains(Iter(a), Sent(Iter(a)), 1); + assert(!ret); +} +{ + ValueT a[] = {}; + auto range = std::ranges::subrange(Iter(a), Sent(Iter(a))); + auto ret = std::ranges::contains(range, 1); + assert(!ret); +} + } + + { // check that no match +{ + ValueT a[] = {13, 1, 21, 4, 5}; + auto ret = std::ranges::contains(Iter(a), Sent(Iter(a + 5)), 10); + assert(!ret); +} +{ + ValueT a[] = {13, 1, 21, 4, 5}; + auto range = std::ranges::subrange(Iter(a), Sent(Iter(a + 5))); + auto ret = std::ranges::contains(range, 10); + assert(!ret); +} + } + + if (!std::is_constant_evaluated()) +comparable_data.clear(); +} +template +class TriviallyComparable { var-const wrote: Thanks for pointing me to the patch. It looks like this is to test an optimization that's specific to `find`. IMO we shouldn't duplicate those tests here, so I'd just remove the `Comparable` and `TriviallyComparable` tests. It might make sense to add a benchmark for `ranges::contains`, though. https://github.com/llvm/llvm-project/pull/65148 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [libc++] Implement ranges::contains (PR #65148)
@@ -0,0 +1,61 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H +#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H + +#include <__algorithm/in_in_result.h> var-const wrote: Sorry, what I mean is that a good and easy way to see if we're testing every constraint is to simply remove or comment out a constraint, run the tests and see if any tests fail. If we're testing everything properly, at least one test will fail -- conversely, if everything passes, that means a lack of test coverage. So what I'm suggesting is to temporarily remove the `projected` constraint in your local copy, run the tests and see if there are any failures. If there are no failures, please see if it's possible to add a test that checks we are using the `projected` concept there as required by the Standard. Happy to help if this explanation isn't clear! https://github.com/llvm/llvm-project/pull/65148 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [libc++] Implement ranges::contains_subrange (PR #66963)
var-const wrote: > > Please make sure you add a description to your PR. This is what usually > > goes into the git log and we want those entries to be as descriptive and > > helpful for folks who read the git logs, thank you. > > Do you have any specific suggestions what should be in the message? The > libc++ "I implement something" patches are most of the time quite > straight-forward, since you can look at the standard and know what's going > on. It's also the best source, since it's the authoritative document here, > and is also what anybody who cares to actually look at the patch should check > against for correctness. +1 -- I'm in favor of descriptive commit messages in general, but in this case I'm not sure what would be useful to add beyond "Implement ranges::contains_subrange". https://github.com/llvm/llvm-project/pull/66963 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)
https://github.com/var-const edited https://github.com/llvm/llvm-project/pull/66963 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,303 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 +// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=200 + +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template +// requires indirect_binary_predicate, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include +#include +#include +#include +#include + +#include "almost_satisfies_types.h" +#include "boolean_testable.h" +#include "test_iterators.h" + +struct NotEqualityComparable {}; + +template +concept HasContainsSubrangeIt = requires(Iter1 first1, Sent1 last1, Iter2 first2, Sent2 last2) { + std::ranges::contains_subrange(first1, last1, first2, last2); +}; + +static_assert(HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); // not indirectly comparable +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); + +template > +concept HasContainsSubrangeR = requires(Range1&& range1, Range2&& range2) { + std::ranges::contains_subrange(std::forward(range1), std::forward(range2)); }; + +static_assert(HasContainsSubrangeR>); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR, UncheckedRange>); // not indirectly comparable +static_assert(!HasContainsSubrangeR, ForwardRangeNotDerivedFrom>); +static_assert(!HasContainsSubrangeR, ForwardRangeNotIncrementable>); +static_assert(!HasContainsSubrangeR, ForwardRangeNotSentinelSemiregular>); +static_assert(!HasContainsSubrangeR, ForwardRangeNotSentinelEqualityComparableWith>); + +template +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))); +auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3))); +{ + [[maybe_unused]] std::same_as decltype(auto) ret = + std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end()); + assert(ret); +} +{ + [[maybe_unused]] std::same_as 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))); +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()); + assert(!ret); +} +{ + bool ret = std::ranges::contains_subrange(whole, subrange); + assert(!ret); +} + } + + { // 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))); +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()); + assert(!ret); +} +{ + bool ret = std::ranges::contains_subrange(whole, subrange); + assert(!ret); +} + } + + { // 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))); +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()); + assert(ret); +} +{ + bool ret = std::ranges::contains_subrange(whole, subrange); + assert(ret); +} + } + + { // range has zero length +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.e
[Lldb-commits] [lldb] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,303 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 +// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=200 + +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template +// requires indirect_binary_predicate, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include +#include +#include +#include +#include + +#include "almost_satisfies_types.h" +#include "boolean_testable.h" +#include "test_iterators.h" + +struct NotEqualityComparable {}; + +template +concept HasContainsSubrangeIt = requires(Iter1 first1, Sent1 last1, Iter2 first2, Sent2 last2) { + std::ranges::contains_subrange(first1, last1, first2, last2); +}; + +static_assert(HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); // not indirectly comparable +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); +static_assert(!HasContainsSubrangeIt); + +template > +concept HasContainsSubrangeR = requires(Range1&& range1, Range2&& range2) { + std::ranges::contains_subrange(std::forward(range1), std::forward(range2)); }; + +static_assert(HasContainsSubrangeR>); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR); +static_assert(!HasContainsSubrangeR, UncheckedRange>); // not indirectly comparable +static_assert(!HasContainsSubrangeR, ForwardRangeNotDerivedFrom>); +static_assert(!HasContainsSubrangeR, ForwardRangeNotIncrementable>); +static_assert(!HasContainsSubrangeR, ForwardRangeNotSentinelSemiregular>); +static_assert(!HasContainsSubrangeR, ForwardRangeNotSentinelEqualityComparableWith>); + +template +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))); +auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3))); +{ + [[maybe_unused]] std::same_as decltype(auto) ret = + std::ranges::contains_subrange(whole.begin(), whole.end(), subrange.begin(), subrange.end()); + assert(ret); +} +{ + [[maybe_unused]] std::same_as 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))); +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()); + assert(!ret); +} +{ + bool ret = std::ranges::contains_subrange(whole, subrange); + assert(!ret); +} + } + + { // 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))); +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()); + assert(!ret); +} +{ + bool ret = std::ranges::contains_subrange(whole, subrange); + assert(!ret); +} + } + + { // 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))); +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()); + assert(ret); +} +{ + bool ret = std::ranges::contains_subrange(whole, subrange); + assert(ret); +} + } + + { // range has zero length +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.e
[Lldb-commits] [lldb] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,303 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 +// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=200 + +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 var-const wrote: This synopsis is for `contains`, not `contains_subrange`. https://github.com/llvm/llvm-project/pull/66963 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)
https://github.com/var-const edited https://github.com/llvm/llvm-project/pull/66963 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)
@@ -0,0 +1,303 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 +// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=200 + +// template S, class T, class Proj = identity> +// requires indirect_binary_predicate, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template +// requires indirect_binary_predicate, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include +#include +#include +#include +#include var-const wrote: Nit: `` seems unused. https://github.com/llvm/llvm-project/pull/66963 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)
https://github.com/var-const requested changes to this pull request. Thank you for the patch! https://github.com/llvm/llvm-project/pull/66963 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits