53 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// constexpr explicit sentinel(sentinel_t<Base> end);12 13#include <cassert>14#include <ranges>15#include <tuple>16#include <utility>17 18struct Sent {19 int i;20 21 friend constexpr bool operator==(std::tuple<int>*, const Sent&) { return true; }22};23 24struct Range : std::ranges::view_base {25 std::tuple<int>* begin() const;26 Sent end();27};28 29// Test explicit30 31static_assert(std::is_constructible_v<std::ranges::sentinel_t<std::ranges::elements_view<Range, 0>>, Sent>);32static_assert(!std::is_convertible_v<Sent, std::ranges::sentinel_t<std::ranges::elements_view<Range, 0>>>);33 34constexpr bool test() {35 // base is init correctly36 {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 47int main(int, char**) {48 test();49 static_assert(test());50 51 return 0;52}53