|
22 | 22 | #include "test_iterators.h" |
23 | 23 | #include "test_range.h" |
24 | 24 |
|
25 | | -using input_view = std::views::all_t<test_range<cpp20_input_iterator>>; |
| 25 | +struct input_view { |
| 26 | + cpp20_input_iterator<int*> begin() const; |
| 27 | + sentinel_wrapper<cpp20_input_iterator<int*>> end() const; |
| 28 | +}; |
| 29 | +template <> inline constexpr bool std::ranges::enable_view<input_view> = true; |
26 | 30 | static_assert(std::ranges::input_range<input_view> && !std::ranges::forward_range<input_view>); |
27 | 31 |
|
28 | | -struct forward_view : std::ranges::view_base { |
29 | | - std::string* begin() const; |
30 | | - std::string* end() const; |
| 32 | +struct forward_view { |
| 33 | + int* begin() const; |
| 34 | + int* end() const; |
31 | 35 | }; |
| 36 | +template <> inline constexpr bool std::ranges::enable_view<forward_view> = true; |
32 | 37 | static_assert(std::ranges::forward_range<forward_view>); |
33 | | -static_assert(std::is_reference_v<std::ranges::range_reference_t<forward_view>>); |
34 | | - |
35 | | -template <class View> |
36 | | -struct Test { |
37 | | - [[no_unique_address]] View view; |
38 | | - unsigned char pad; |
39 | | -}; |
40 | 38 |
|
41 | 39 | using CV1 = std::ranges::chunk_view<input_view>; |
42 | 40 | // Expected CV1 (with View == input) layout: |
43 | | -// [[no_unique_address]] _View __base_ // offset: 0 |
44 | | -// [[no_unique_address]] range_difference_t<_View> __n_ // offset: sizeof(std::ptrdiff_t) |
45 | | -// [[no_unique_address]] range_difference_t<_View> __remainder_ // offset: sizeof(std::ptrdiff_t) |
46 | | -// [[no_unique_address]] __non_propagating_cache<iterator_t<_View>> __current_ // offset: ? |
47 | | -// TODO: hmmm I'm a pure new C++ learner (having been exposed to C++ for 2 years) |
48 | | -// and I do not know about the memory layout here too... |
49 | | -// What is the layout like? |
| 41 | +// [[no_unique_address]] _View __base_ // size: 0 |
| 42 | +// [[no_unique_address]] range_difference_t<_View> __n_ // size: sizeof(ptrdiff_t) |
| 43 | +// [[no_unique_address]] range_difference_t<_View> __remainder_ // size: sizeof(ptrdiff_t) |
| 44 | +// [[no_unique_address]] __non_propagating_cache<iterator_t<_View>> __current_ // size: sizeof(__non_propagating_cache<cpp20_input_iterator<int*>>), align: std::ptrdiff_t |
| 45 | +static_assert(sizeof(CV1) == /*sizeof(__base_) == 0 + */ sizeof(std::ptrdiff_t) * 2 + sizeof(std::ranges::__non_propagating_cache<cpp20_input_iterator<int*>>)); |
50 | 46 |
|
51 | 47 | using CV2 = std::ranges::chunk_view<forward_view>; |
52 | 48 | // Expected CV2 (with View >= forward) layout: |
53 | | -// [[no_unique_address]] _View __base_ // offset: 0 |
54 | | -// [[no_unique_address]] range_difference_t<_View> // offset: sizeof(std::ptrdiff_t) |
55 | | -static_assert(sizeof(CV2) == sizeof(std::ptrdiff_t)); |
56 | | -static_assert(sizeof(Test<CV2>) == sizeof(std::ptrdiff_t) * 2); |
| 49 | +// [[no_unique_address]] _View __base_ // size: 0 |
| 50 | +// [[no_unique_address]] range_difference_t<_View> // size: sizeof(ptrdiff_t) |
| 51 | +static_assert(sizeof(CV2) == /*sizeof(__base_) == 0 + */ sizeof(std::ptrdiff_t)); |
0 commit comments