1*042dc3c4SHui Xie //===----------------------------------------------------------------------===//
2*042dc3c4SHui Xie //
3*042dc3c4SHui Xie // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*042dc3c4SHui Xie // See https://llvm.org/LICENSE.txt for license information.
5*042dc3c4SHui Xie // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*042dc3c4SHui Xie //
7*042dc3c4SHui Xie //===----------------------------------------------------------------------===//
8*042dc3c4SHui Xie
9*042dc3c4SHui Xie // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10*042dc3c4SHui Xie // UNSUPPORTED: libcpp-has-no-incomplete-ranges
11*042dc3c4SHui Xie
12*042dc3c4SHui Xie // sentinel() = default;
13*042dc3c4SHui Xie
14*042dc3c4SHui Xie #include <cassert>
15*042dc3c4SHui Xie #include <ranges>
16*042dc3c4SHui Xie #include <tuple>
17*042dc3c4SHui Xie
18*042dc3c4SHui Xie struct PODSentinel {
19*042dc3c4SHui Xie bool b; // deliberately uninitialised
20*042dc3c4SHui Xie
operator ==(int *,const PODSentinel & s)21*042dc3c4SHui Xie friend constexpr bool operator==(int*, const PODSentinel& s) { return s.b; }
22*042dc3c4SHui Xie };
23*042dc3c4SHui Xie
24*042dc3c4SHui Xie struct Range : std::ranges::view_base {
25*042dc3c4SHui Xie int* begin() const;
26*042dc3c4SHui Xie PODSentinel end();
27*042dc3c4SHui Xie };
28*042dc3c4SHui Xie
test()29*042dc3c4SHui Xie constexpr bool test() {
30*042dc3c4SHui Xie {
31*042dc3c4SHui Xie using R = std::ranges::zip_view<Range>;
32*042dc3c4SHui Xie using Sentinel = std::ranges::sentinel_t<R>;
33*042dc3c4SHui Xie static_assert(!std::is_same_v<Sentinel, std::ranges::iterator_t<R>>);
34*042dc3c4SHui Xie
35*042dc3c4SHui Xie std::ranges::iterator_t<R> it;
36*042dc3c4SHui Xie
37*042dc3c4SHui Xie Sentinel s1;
38*042dc3c4SHui Xie assert(it != s1); // PODSentinel.b is initialised to false
39*042dc3c4SHui Xie
40*042dc3c4SHui Xie Sentinel s2 = {};
41*042dc3c4SHui Xie assert(it != s2); // PODSentinel.b is initialised to false
42*042dc3c4SHui Xie }
43*042dc3c4SHui Xie return true;
44*042dc3c4SHui Xie }
45*042dc3c4SHui Xie
main(int,char **)46*042dc3c4SHui Xie int main(int, char**) {
47*042dc3c4SHui Xie test();
48*042dc3c4SHui Xie static_assert(test());
49*042dc3c4SHui Xie
50*042dc3c4SHui Xie return 0;
51*042dc3c4SHui Xie }
52