xref: /llvm-project/libcxx/test/std/ranges/range.adaptors/range.split/ctor.default.pass.cpp (revision a2b3ab8f7786b9bb6e1b8bbb01b88d4bbe28af69)
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 // constexpr split_view() requires
12 //   default_initializable<V> && default_initializable<Pattern> = default;
13 
14 #include <cassert>
15 #include <ranges>
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   int* begin() const;
25   int* end() const;
26 };
27 
28 // clang-format off
29 static_assert( std::is_default_constructible_v<std::ranges::split_view<View<true >, View<true >>>);
30 static_assert(!std::is_default_constructible_v<std::ranges::split_view<View<false>, View<true >>>);
31 static_assert(!std::is_default_constructible_v<std::ranges::split_view<View<true >, View<false>>>);
32 static_assert(!std::is_default_constructible_v<std::ranges::split_view<View<false>, View<false>>>);
33 // clang-format on
34 
test()35 constexpr bool test() {
36   {
37     std::ranges::split_view<View<true>, View<true>> sv = {};
38     assert(sv.base().i == 42);
39   }
40   return true;
41 }
42 
main(int,char **)43 int main(int, char**) {
44   test();
45   static_assert(test());
46   return 0;
47 }
48