xref: /llvm-project/libcxx/test/std/ranges/range.adaptors/range.elements/sentinel/ctor.base.pass.cpp (revision 94461822c75d5080bf648f86552f7a59b76905c9)
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(sentinel_t<Base> end);
12 
13 #include <cassert>
14 #include <ranges>
15 #include <tuple>
16 #include <utility>
17 
18 struct Sent {
19   int i;
20 
operator ==(std::tuple<int> *,const Sent &)21   friend constexpr bool operator==(std::tuple<int>*, const Sent&) { return true; }
22 };
23 
24 struct Range : std::ranges::view_base {
25   std::tuple<int>* begin() const;
26   Sent end();
27 };
28 
29 // Test explicit
30 
31 static_assert(std::is_constructible_v<std::ranges::sentinel_t<std::ranges::elements_view<Range, 0>>, Sent>);
32 static_assert(!std::is_convertible_v<Sent, std::ranges::sentinel_t<std::ranges::elements_view<Range, 0>>>);
33 
test()34 constexpr bool test() {
35   // base is init correctly
36   {
37     using R        = std::ranges::elements_view<Range, 0>;
38     using Sentinel = std::ranges::sentinel_t<R>;
39 
40     Sentinel s1(Sent{5});
41     assert(s1.base().i == 5);
42   }
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