//===----------------------------------------------------------------------===// // // 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(); // constexpr auto begin() const requires range; #include #include #include #include #include "test_iterators.h" #include "types.h" struct MutableView : std::ranges::view_base { int* begin(); sentinel_wrapper end(); }; template concept BeginEnabled = requires(View v) { v.begin(); }; constexpr bool test() { int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8}; { static_assert( BeginEnabled const&>); static_assert( BeginEnabled&>); static_assert(!BeginEnabled const&>); } { SizedRandomAccessView view{buf, buf + 8}; std::ranges::common_view common(view); std::same_as auto begin = common.begin(); assert(begin == std::ranges::begin(view)); } { SizedRandomAccessView view{buf, buf + 8}; std::ranges::common_view const common(view); std::same_as auto begin = common.begin(); assert(begin == std::ranges::begin(view)); } return true; } int main(int, char**) { test(); static_assert(test()); // The non-constexpr tests: int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8}; { SizedForwardView view{buf, buf + 8}; std::ranges::common_view common(view); using CommonIter = std::common_iterator>; std::same_as auto begin = common.begin(); assert(begin == std::ranges::begin(view)); std::same_as auto cbegin = std::as_const(common).begin(); assert(cbegin == std::ranges::begin(view)); } { MoveOnlyView view{buf, buf + 8}; std::ranges::common_view common(std::move(view)); using CommonIter = std::common_iterator>; std::same_as auto begin = common.begin(); assert(begin == std::ranges::begin(view)); } { CopyableView view{buf, buf + 8}; std::ranges::common_view const common(view); using CommonIter = std::common_iterator>; std::same_as auto begin = common.begin(); assert(begin == std::ranges::begin(view)); } return 0; }