| 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 |
|
| 18 |
struct PODIter : IterBase<PODIter> { |
| 19 |
int i; // deliberately uninitialised |
| 20 |
}; |
| 21 |
|
| 22 |
struct IterDefaultCtrView : std::ranges::view_base { |
| 23 |
PODIter begin() const; |
| 24 |
PODIter end() const; |
| 25 |
}; |
| 26 |
|
| 27 |
struct 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 |
|
| 32 |
template <class View, std::size_t N> |
| 33 |
using ElementsIter = std::ranges::iterator_t<std::ranges::elements_view<View, N>>; |
| 34 |
|
| 35 |
static_assert(!std::default_initializable<ElementsIter<IterNoDefaultCtrView, 0>>); |
| 36 |
static_assert(std::default_initializable<ElementsIter<IterDefaultCtrView, 0>>); |
| 37 |
|
| 38 |
constexpr 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 |
|
| 53 |
int main(int, char**) { |
| 54 |
test(); |
| 55 |
static_assert(test()); |
| 56 |
|
| 57 |
return 0; |
| 58 |
} |