110 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LIBCXX_TEST_SUPPORT_TEST_RANGE_H10#define LIBCXX_TEST_SUPPORT_TEST_RANGE_H11 12#include <concepts>13#include <functional>14#include <iterator>15#include <ranges>16#include <type_traits>17 18#include "test_iterators.h"19 20#if TEST_STD_VER < 1721# error "test/support/test_range.h" can only be included in builds supporting ranges22#endif23 24struct sentinel {25 bool operator==(std::input_or_output_iterator auto const&) const;26};27 28template <template <class...> class I, class T = int>29 requires std::input_or_output_iterator<I<T*> >30struct test_range {31 I<T*> begin();32 I<T const*> begin() const;33 sentinel end();34 sentinel end() const;35};36 37template <template <class...> class I, class T = int>38 requires std::input_or_output_iterator<I<T*> >39struct test_non_const_range {40 I<T*> begin();41 sentinel end();42};43 44template <template <class...> class I, class T = int>45 requires std::input_or_output_iterator<I<T*> >46struct test_common_range {47 I<T*> begin();48 I<T const*> begin() const;49 I<T*> end();50 I<T const*> end() const;51};52 53template <template <class...> class I, class T = int>54 requires std::input_or_output_iterator<I<T*> >55struct test_non_const_common_range {56 I<T*> begin();57 I<T*> end();58};59 60template <template <class...> class I, class T = int>61 requires std::input_or_output_iterator<I<T*> >62struct test_view : std::ranges::view_base {63 I<T*> begin();64 I<T const*> begin() const;65 sentinel end();66 sentinel end() const;67};68 69template <class T = int>70struct BorrowedRange {71 T* begin() const;72 T* end() const;73 BorrowedRange(BorrowedRange&&) = delete;74};75template <class T>76inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange<T>> = true;77static_assert(!std::ranges::view<BorrowedRange<>>);78static_assert(std::ranges::borrowed_range<BorrowedRange<>>);79 80using BorrowedView = std::ranges::empty_view<int>;81static_assert(std::ranges::view<BorrowedView>);82static_assert(std::ranges::borrowed_range<BorrowedView>);83 84using NonBorrowedView = std::ranges::single_view<int>;85static_assert(std::ranges::view<NonBorrowedView>);86static_assert(!std::ranges::borrowed_range<NonBorrowedView>);87 88template <class Range>89concept simple_view =90 std::ranges::view<Range> && std::ranges::range<const Range> &&91 std::same_as<std::ranges::iterator_t<Range>, std::ranges::iterator_t<const Range>> &&92 std::same_as<std::ranges::sentinel_t<Range>, std::ranges::sentinel_t<const Range>>;93 94template <class View, class T>95concept CanBePiped = requires(View&& view, T&& t) {96 { std::forward<View>(view) | std::forward<T>(t) };97};98 99// See [concept.equalitycomparable]100template <class T, class U>101concept weakly_equality_comparable_with =102 requires(const std::remove_reference_t<T>& t, const std::remove_reference_t<U>& u) {103 { t == u } -> std::same_as<bool>;104 { t != u } -> std::same_as<bool>;105 { u == t } -> std::same_as<bool>;106 { u != t } -> std::same_as<bool>;107 };108 109#endif // LIBCXX_TEST_SUPPORT_TEST_RANGE_H110