xref: /llvm-project/libcxx/test/std/ranges/range.adaptors/range.split/sentinel/ctor.parent.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 explicit sentinel(split_view& parent);
12 
13 #include <cassert>
14 #include <ranges>
15 #include <type_traits>
16 
17 #include "test_iterators.h"
18 
19 // test explicit
20 using Range     = std::ranges::subrange<int*, sentinel_wrapper<int*>>;
21 using SplitView = std::ranges::split_view<Range, std::ranges::single_view<int>>;
22 using SplitSent = std::ranges::sentinel_t<SplitView>;
23 
24 static_assert(std::is_constructible_v<SplitSent, SplitView&>);
25 static_assert(!std::is_convertible_v<SplitView&, SplitSent>);
26 
test()27 constexpr bool test() {
28   {
29     int buffer[] = {0, 1, 2};
30     Range input{buffer, sentinel_wrapper<int*>(buffer + 3)};
31     SplitView sv(input, -1);
32     auto it = sv.begin();
33 
34     SplitSent sent(sv);
35     assert(sent != it);
36 
37     ++it;
38     assert(sent == it);
39   }
40 
41   return true;
42 }
43 
main(int,char **)44 int main(int, char**) {
45   test();
46   static_assert(test());
47 
48   return 0;
49 }
50