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
20template <class T>
21struct 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
32using IntBufferViewBase = BufferViewBase<int>;
33
34struct SimpleView : IntBufferViewBase {
35 using IntBufferViewBase::IntBufferViewBase;
36 constexpr int* begin() const { return buffer_; }
37 constexpr int* end() const { return buffer_ + size_; }
38};
39static_assert(simple_view<SimpleView>);
40
41struct ConstNotRange : IntBufferViewBase {
42 using IntBufferViewBase::IntBufferViewBase;
43 constexpr int* begin() { return buffer_; }
44 constexpr int* end() { return buffer_ + size_; }
45};
46static_assert(std::ranges::view<ConstNotRange>);
47static_assert(!std::ranges::range<const ConstNotRange>);
48
49struct 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};
56static_assert(std::ranges::view<NonSimple>);
57static_assert(!simple_view<NonSimple>);
58
59#endif // TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_TAKE_WHILE_TYPES_H
60

source code of libcxx/test/std/ranges/range.adaptors/range.take.while/types.h