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> BufferViewBaseBufferViewBase26 constexpr BufferViewBase(T (&b)[N]) : buffer_(b), size_(N) {} 27 28 template <std::size_t N> BufferViewBaseBufferViewBase29 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; beginSimpleView36 constexpr int* begin() const { return buffer_; } endSimpleView37 constexpr int* end() const { return buffer_ + size_; } 38 }; 39 static_assert(simple_view<SimpleView>); 40 41 struct ConstNotRange : IntBufferViewBase { 42 using IntBufferViewBase::IntBufferViewBase; beginConstNotRange43 constexpr int* begin() { return buffer_; } endConstNotRange44 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; beginNonSimple51 constexpr const int* begin() const { return buffer_; } endNonSimple52 constexpr const int* end() const { return buffer_ + size_; } beginNonSimple53 constexpr int* begin() { return buffer_; } endNonSimple54 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