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, c++20 |
10 | |
11 | // iterator() = default; |
12 | |
13 | #include <ranges> |
14 | #include <tuple> |
15 | |
16 | #include "../types.h" |
17 | |
18 | struct PODIter { |
19 | int i; // deliberately uninitialised |
20 | |
21 | using iterator_category = std::random_access_iterator_tag; |
22 | using value_type = int; |
23 | using difference_type = std::intptr_t; |
24 | |
25 | constexpr int operator*() const { return i; } |
26 | |
27 | constexpr PODIter& operator++() { return *this; } |
28 | constexpr void operator++(int) {} |
29 | |
30 | friend constexpr bool operator==(const PODIter&, const PODIter&) = default; |
31 | }; |
32 | |
33 | struct IterDefaultCtrView : std::ranges::view_base { |
34 | PODIter begin() const; |
35 | PODIter end() const; |
36 | }; |
37 | |
38 | struct IterNoDefaultCtrView : std::ranges::view_base { |
39 | cpp20_input_iterator<int*> begin() const; |
40 | sentinel_wrapper<cpp20_input_iterator<int*>> end() const; |
41 | }; |
42 | |
43 | template <class... Views> |
44 | using zip_iter = std::ranges::iterator_t<std::ranges::zip_view<Views...>>; |
45 | |
46 | static_assert(!std::default_initializable<zip_iter<IterNoDefaultCtrView>>); |
47 | static_assert(!std::default_initializable<zip_iter<IterNoDefaultCtrView, IterDefaultCtrView>>); |
48 | static_assert(!std::default_initializable<zip_iter<IterNoDefaultCtrView, IterNoDefaultCtrView>>); |
49 | static_assert(std::default_initializable<zip_iter<IterDefaultCtrView>>); |
50 | static_assert(std::default_initializable<zip_iter<IterDefaultCtrView, IterDefaultCtrView>>); |
51 | |
52 | constexpr bool test() { |
53 | using ZipIter = zip_iter<IterDefaultCtrView>; |
54 | { |
55 | ZipIter iter; |
56 | auto [x] = *iter; |
57 | assert(x == 0); // PODIter has to be initialised to have value 0 |
58 | } |
59 | |
60 | { |
61 | ZipIter iter = {}; |
62 | auto [x] = *iter; |
63 | assert(x == 0); // PODIter has to be initialised to have value 0 |
64 | } |
65 | return true; |
66 | } |
67 | |
68 | int main(int, char**) { |
69 | test(); |
70 | static_assert(test()); |
71 | |
72 | return 0; |
73 | } |
74 | |