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