//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 // constexpr sentinel(sentinel s); #include #include #include "../types.h" template struct convertible_sentinel_wrapper { explicit convertible_sentinel_wrapper() = default; constexpr convertible_sentinel_wrapper(const T& it) : it_(it) {} template requires std::convertible_to constexpr convertible_sentinel_wrapper(const convertible_sentinel_wrapper& other) : it_(other.it_) {} constexpr friend bool operator==(convertible_sentinel_wrapper const& self, const T& other) { return self.it_ == other; } T it_; }; struct NonSimpleNonCommonConvertibleView : IntBufferView { using IntBufferView::IntBufferView; constexpr int* begin() { return buffer_; } constexpr const int* begin() const { return buffer_; } constexpr convertible_sentinel_wrapper end() { return convertible_sentinel_wrapper(buffer_ + size_); } constexpr convertible_sentinel_wrapper end() const { return convertible_sentinel_wrapper(buffer_ + size_); } }; static_assert(!std::ranges::common_range); static_assert(std::ranges::random_access_range); static_assert(!std::ranges::sized_range); static_assert(std::convertible_to, std::ranges::sentinel_t>); static_assert(!simple_view); constexpr bool test() { int buffer1[4] = {1, 2, 3, 4}; int buffer2[5] = {1, 2, 3, 4, 5}; std::ranges::zip_view v{NonSimpleNonCommonConvertibleView(buffer1), NonSimpleNonCommonConvertibleView(buffer2)}; static_assert(!std::ranges::common_range); auto sent1 = v.end(); std::ranges::sentinel_t sent2 = sent1; static_assert(!std::is_same_v); assert(v.begin() != sent2); assert(std::as_const(v).begin() != sent2); assert(v.begin() + 4 == sent2); assert(std::as_const(v).begin() + 4 == sent2); // Cannot create a non-const iterator from a const iterator. static_assert(!std::constructible_from); return true; } int main(int, char**) { test(); static_assert(test()); return 0; }