| 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 |
// elements_view() requires default_initializable<V> = default; |
| 12 |
|
| 13 |
#include <cassert> |
| 14 |
#include <ranges> |
| 15 |
#include <tuple> |
| 16 |
#include <type_traits> |
| 17 |
|
| 18 |
template <bool DefaultInitializable> |
| 19 |
struct View : std::ranges::view_base { |
| 20 |
int i = 42; |
| 21 |
constexpr explicit View() |
| 22 |
requires DefaultInitializable |
| 23 |
= default; |
| 24 |
std::tuple<int>* begin() const; |
| 25 |
std::tuple<int>* end() const; |
| 26 |
}; |
| 27 |
|
| 28 |
|
| 29 |
// clang-format off |
| 30 |
static_assert( std::is_default_constructible_v<std::ranges::elements_view<View<true >, 0>>); |
| 31 |
static_assert(!std::is_default_constructible_v<std::ranges::elements_view<View<false>, 0>>); |
| 32 |
// clang-format on |
| 33 |
|
| 34 |
constexpr bool test() { |
| 35 |
{ |
| 36 |
std::ranges::elements_view<View<true>, 0> ev = {}; |
| 37 |
assert(ev.base().i == 42); |
| 38 |
} |
| 39 |
|
| 40 |
return true; |
| 41 |
} |
| 42 |
|
| 43 |
int main(int, char**) { |
| 44 |
test(); |
| 45 |
static_assert(test()); |
| 46 |
return 0; |
| 47 |
} |