xref: /llvm-project/libcxx/test/std/ranges/range.adaptors/range.split/sentinel/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 // sentinel() = default;
12 
13 #include <cassert>
14 #include <ranges>
15 
16 struct PODSentinel {
17   int i;
18 
operator ==(int *,const PODSentinel & p)19   friend constexpr bool operator==(int*, const PODSentinel& p) { return p.i == 0; }
20 };
21 
22 struct Range : std::ranges::view_base {
23   int* begin() const;
24   PODSentinel end();
25 };
26 
test()27 constexpr bool test() {
28   using SplitView = std::ranges::split_view<Range, Range>;
29   using SplitIter = std::ranges::iterator_t<SplitView>;
30   using SplitSent = std::ranges::sentinel_t<SplitView>;
31   static_assert(!std::is_same_v<SplitSent, SplitIter>);
32 
33   {
34     SplitIter it;
35     SplitSent s;
36     assert(s == it); // to make sure that s.__end_.i is initialised to 0;
37   }
38 
39   {
40     SplitIter it;
41     SplitSent s = {};
42     assert(s == it); // to make sure that s.__end_.i is initialised to 0;
43   }
44   return true;
45 }
46 
main(int,char **)47 int main(int, char**) {
48   test();
49   static_assert(test());
50 
51   return 0;
52 }
53