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// iterator() requires default_initializable<iterator_t<Base>> = default;
12
13#include <ranges>
14#include <tuple>
15
16#include "../types.h"
17
18struct PODIter : IterBase<PODIter> {
19 int i; // deliberately uninitialised
20};
21
22struct IterDefaultCtrView : std::ranges::view_base {
23 PODIter begin() const;
24 PODIter end() const;
25};
26
27struct IterNoDefaultCtrView : std::ranges::view_base {
28 cpp20_input_iterator<std::tuple<int>*> begin() const;
29 sentinel_wrapper<cpp20_input_iterator<std::tuple<int>*>> end() const;
30};
31
32template <class View, std::size_t N>
33using ElementsIter = std::ranges::iterator_t<std::ranges::elements_view<View, N>>;
34
35static_assert(!std::default_initializable<ElementsIter<IterNoDefaultCtrView, 0>>);
36static_assert(std::default_initializable<ElementsIter<IterDefaultCtrView, 0>>);
37
38constexpr bool test() {
39 using Iter = ElementsIter<IterDefaultCtrView, 0>;
40 {
41 Iter iter;
42 assert(iter.base().i == 0); // PODIter has to be initialised to have value 0
43 }
44
45 {
46 Iter iter = {};
47 assert(iter.base().i == 0); // PODIter has to be initialised to have value 0
48 }
49
50 return true;
51}
52
53int main(int, char**) {
54 test();
55 static_assert(test());
56
57 return 0;
58}
59

source code of libcxx/test/std/ranges/range.adaptors/range.elements/iterator/ctor.default.pass.cpp