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 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
10 | |
11 | // transform_view::<iterator>::transform_view::<iterator>(); |
12 | |
13 | #include <ranges> |
14 | |
15 | #include "test_macros.h" |
16 | #include "../types.h" |
17 | |
18 | struct NoDefaultInit { |
19 | typedef std::random_access_iterator_tag iterator_category; |
20 | typedef int value_type; |
21 | typedef std::ptrdiff_t difference_type; |
22 | typedef int* pointer; |
23 | typedef int& reference; |
24 | typedef NoDefaultInit self; |
25 | |
26 | NoDefaultInit(int*); |
27 | |
28 | reference operator*() const; |
29 | pointer operator->() const; |
30 | auto operator<=>(const self&) const = default; |
31 | bool operator==(int *) const; |
32 | |
33 | self& operator++(); |
34 | self operator++(int); |
35 | |
36 | self& operator--(); |
37 | self operator--(int); |
38 | |
39 | self& operator+=(difference_type n); |
40 | self operator+(difference_type n) const; |
41 | friend self operator+(difference_type n, self x); |
42 | |
43 | self& operator-=(difference_type n); |
44 | self operator-(difference_type n) const; |
45 | difference_type operator-(const self&) const; |
46 | |
47 | reference operator[](difference_type n) const; |
48 | }; |
49 | |
50 | struct IterNoDefaultInitView : std::ranges::view_base { |
51 | NoDefaultInit begin() const; |
52 | int *end() const; |
53 | NoDefaultInit begin(); |
54 | int *end(); |
55 | }; |
56 | |
57 | constexpr bool test() { |
58 | std::ranges::transform_view<MoveOnlyView, PlusOne> transformView; |
59 | auto iter = std::move(transformView).begin(); |
60 | std::ranges::iterator_t<std::ranges::transform_view<MoveOnlyView, PlusOne>> i2(iter); |
61 | (void)i2; |
62 | std::ranges::iterator_t<const std::ranges::transform_view<MoveOnlyView, PlusOne>> constIter(iter); |
63 | (void)constIter; |
64 | |
65 | |
66 | static_assert( std::default_initializable<std::ranges::iterator_t<std::ranges::transform_view<MoveOnlyView, PlusOne>>>); |
67 | static_assert(!std::default_initializable<std::ranges::iterator_t<std::ranges::transform_view<IterNoDefaultInitView, PlusOne>>>); |
68 | |
69 | return true; |
70 | } |
71 | |
72 | int main(int, char**) { |
73 | test(); |
74 | static_assert(test()); |
75 | |
76 | return 0; |
77 | } |
78 | |