[WebAssembly] Fix asan issue from https://reviews.llvm.org/D121349
[llvm-project.git] / libcxx / test / support / test_range.h
blob93fe95547e941f871e240e54c80e26755ab6f500
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef LIBCXX_TEST_SUPPORT_TEST_RANGE_H
9 #define LIBCXX_TEST_SUPPORT_TEST_RANGE_H
11 #include <iterator>
12 #include <ranges>
14 #include "test_iterators.h"
16 #if _LIBCPP_STD_VER < 17
17 #error "test/support/test_range.h" can only be included in builds supporting ranges
18 #endif
20 struct sentinel {
21 bool operator==(std::input_or_output_iterator auto const&) const;
24 template <template <class...> class I>
25 requires std::input_or_output_iterator<I<int*> >
26 struct test_range {
27 I<int*> begin();
28 I<int const*> begin() const;
29 sentinel end();
30 sentinel end() const;
33 template <template <class...> class I>
34 requires std::input_or_output_iterator<I<int*> >
35 struct test_non_const_range {
36 I<int*> begin();
37 sentinel end();
40 template <template <class...> class I>
41 requires std::input_or_output_iterator<I<int*> >
42 struct test_common_range {
43 I<int*> begin();
44 I<int const*> begin() const;
45 I<int*> end();
46 I<int const*> end() const;
49 template <template <class...> class I>
50 requires std::input_or_output_iterator<I<int*> >
51 struct test_non_const_common_range {
52 I<int*> begin();
53 I<int*> end();
56 template <template <class...> class I>
57 requires std::input_or_output_iterator<I<int*> >
58 struct test_view : std::ranges::view_base {
59 I<int*> begin();
60 I<int const*> begin() const;
61 sentinel end();
62 sentinel end() const;
65 struct BorrowedRange {
66 int *begin() const;
67 int *end() const;
68 BorrowedRange(BorrowedRange&&) = delete;
70 template<> inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true;
71 static_assert(!std::ranges::view<BorrowedRange>);
72 static_assert(std::ranges::borrowed_range<BorrowedRange>);
74 using BorrowedView = std::ranges::empty_view<int>;
75 static_assert(std::ranges::view<BorrowedView>);
76 static_assert(std::ranges::borrowed_range<BorrowedView>);
78 using NonBorrowedView = std::ranges::single_view<int>;
79 static_assert(std::ranges::view<NonBorrowedView>);
80 static_assert(!std::ranges::borrowed_range<NonBorrowedView>);
82 #endif // LIBCXX_TEST_SUPPORT_TEST_RANGE_H