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 | |
9 | #ifndef TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_TAKE_WHILE_TYPES_H |
10 | #define TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_TAKE_WHILE_TYPES_H |
11 | |
12 | #include <array> |
13 | #include <functional> |
14 | #include <ranges> |
15 | |
16 | #include "test_macros.h" |
17 | #include "test_iterators.h" |
18 | #include "test_range.h" |
19 | |
20 | template <class T> |
21 | struct BufferViewBase : std::ranges::view_base { |
22 | T* buffer_; |
23 | std::size_t size_; |
24 | |
25 | template <std::size_t N> |
26 | constexpr BufferViewBase(T (&b)[N]) : buffer_(b), size_(N) {} |
27 | |
28 | template <std::size_t N> |
29 | constexpr BufferViewBase(std::array<T, N>& arr) : buffer_(arr.data()), size_(N) {} |
30 | }; |
31 | |
32 | using IntBufferViewBase = BufferViewBase<int>; |
33 | |
34 | struct SimpleView : IntBufferViewBase { |
35 | using IntBufferViewBase::IntBufferViewBase; |
36 | constexpr int* begin() const { return buffer_; } |
37 | constexpr int* end() const { return buffer_ + size_; } |
38 | }; |
39 | static_assert(simple_view<SimpleView>); |
40 | |
41 | struct ConstNotRange : IntBufferViewBase { |
42 | using IntBufferViewBase::IntBufferViewBase; |
43 | constexpr int* begin() { return buffer_; } |
44 | constexpr int* end() { return buffer_ + size_; } |
45 | }; |
46 | static_assert(std::ranges::view<ConstNotRange>); |
47 | static_assert(!std::ranges::range<const ConstNotRange>); |
48 | |
49 | struct NonSimple : IntBufferViewBase { |
50 | using IntBufferViewBase::IntBufferViewBase; |
51 | constexpr const int* begin() const { return buffer_; } |
52 | constexpr const int* end() const { return buffer_ + size_; } |
53 | constexpr int* begin() { return buffer_; } |
54 | constexpr int* end() { return buffer_ + size_; } |
55 | }; |
56 | static_assert(std::ranges::view<NonSimple>); |
57 | static_assert(!simple_view<NonSimple>); |
58 | |
59 | #endif // TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_TAKE_WHILE_TYPES_H |
60 | |