================ @@ -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 +// +//===----------------------------------------------------------------------===// + +// <algorithm> + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 +// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=2000000 + +// template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity> +// requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*> +// constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23 + +// template<input_range R, class T, class Proj = identity> +// requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*> +// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23 + +#include <algorithm> +#include <array> +#include <cassert> +#include <ranges> +#include <vector> + +#include "almost_satisfies_types.h" +#include "boolean_testable.h" +#include "test_iterators.h" + +struct NotEqualityComparable {}; + +template <class Iter1, class Sent1 = Iter1, class Iter2 = int*, class Sent2 = Iter2> +concept HasContainsSubrangeIt = requires(Iter1 first1, Sent1 last1, Iter2 first2, Sent2 last2) { + std::ranges::contains_subrange(first1, last1, first2, last2); +}; + +static_assert(HasContainsSubrangeIt<int*>); +static_assert(!HasContainsSubrangeIt<ForwardIteratorNotDerivedFrom>); +static_assert(!HasContainsSubrangeIt<ForwardIteratorNotIncrementable>); +static_assert(!HasContainsSubrangeIt<int*, SentinelForNotSemiregular>); +static_assert(!HasContainsSubrangeIt<int*, int*, int**>); // not indirectly comparable +static_assert(!HasContainsSubrangeIt<int*, SentinelForNotWeaklyEqualityComparableWith>); +static_assert(!HasContainsSubrangeIt<int*, int*, ForwardIteratorNotDerivedFrom>); +static_assert(!HasContainsSubrangeIt<int*, int*, ForwardIteratorNotIncrementable>); +static_assert(!HasContainsSubrangeIt<int*, int*, int*, SentinelForNotSemiregular>); +static_assert(!HasContainsSubrangeIt<int*, int*, int*, SentinelForNotWeaklyEqualityComparableWith>); + +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)); }; + +static_assert(HasContainsSubrangeR<UncheckedRange<int*>>); +static_assert(!HasContainsSubrangeR<ForwardRangeNotDerivedFrom>); +static_assert(!HasContainsSubrangeR<ForwardIteratorNotIncrementable>); +static_assert(!HasContainsSubrangeR<ForwardRangeNotSentinelSemiregular>); +static_assert(!HasContainsSubrangeR<ForwardRangeNotSentinelEqualityComparableWith>); +static_assert(!HasContainsSubrangeR<UncheckedRange<int*>, UncheckedRange<int**>>); // not indirectly comparable +static_assert(!HasContainsSubrangeR<UncheckedRange<int*>, ForwardRangeNotDerivedFrom>); +static_assert(!HasContainsSubrangeR<UncheckedRange<int*>, ForwardRangeNotIncrementable>); +static_assert(!HasContainsSubrangeR<UncheckedRange<int*>, ForwardRangeNotSentinelSemiregular>); +static_assert(!HasContainsSubrangeR<UncheckedRange<int*>, ForwardRangeNotSentinelEqualityComparableWith>); + +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))); + auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3))); + { + [[maybe_unused]] std::same_as<bool> decltype(auto) ret = ---------------- var-const wrote:
I think this `[[maybe_unused]]` is unnecessary because `ret` is being asserted on below. https://github.com/llvm/llvm-project/pull/66963 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits