//===----------------------------------------------------------------------===// // // 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 // constexpr auto begin() requires (!simple-view) // constexpr auto begin() const requires range #include #include #include #include #include #include "types.h" template concept HasConstBegin = requires(const T ct) { ct.begin(); }; template concept HasBegin = requires(T t) { t.begin(); }; template concept HasConstAndNonConstBegin = HasConstBegin && // because const begin and non-const begin returns different types (iterator, iterator) requires(T t, const T ct) { requires !std::same_as; }; template concept HasOnlyNonConstBegin = HasBegin && !HasConstBegin; template concept HasOnlyConstBegin = HasConstBegin && !HasConstAndNonConstBegin; struct NoConstBeginView : TupleBufferView { using TupleBufferView::TupleBufferView; constexpr std::tuple* begin() { return buffer_; } constexpr std::tuple* end() { return buffer_ + size_; } }; // simple-view static_assert(HasOnlyConstBegin>); // !simple-view && range static_assert(HasConstAndNonConstBegin>); // !range static_assert(HasOnlyNonConstBegin>); constexpr bool test() { std::tuple buffer[] = {{1}, {2}}; { // underlying iterator should be pointing to the first element auto ev = std::views::elements<0>(buffer); auto iter = ev.begin(); assert(&(*iter) == &std::get<0>(buffer[0])); } { // underlying range models simple-view auto v = std::views::elements<0>(SimpleCommon{buffer}); static_assert(std::is_same_v); assert(v.begin() == std::as_const(v).begin()); auto&& r = *std::as_const(v).begin(); assert(&r == &std::get<0>(buffer[0])); } { // underlying const R is not a range auto v = std::views::elements<0>(NoConstBeginView{buffer}); auto&& r = *v.begin(); assert(&r == &std::get<0>(buffer[0])); } return true; } int main(int, char**) { test(); static_assert(test()); return 0; }