61 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++17, c++2010 11// <ranges>12 13// constexpr Pred const& pred() const;14 15#include <ranges>16 17#include <cassert>18#include <concepts>19 20struct Range : std::ranges::view_base {21 int* begin() const;22 int* end() const;23};24 25struct Pred {26 bool operator()(int, int) const;27 int value;28};29 30constexpr bool test() {31 {32 Pred pred{42};33 std::ranges::chunk_by_view<Range, Pred> const view(Range{}, pred);34 std::same_as<Pred const&> decltype(auto) result = view.pred();35 assert(result.value == 42);36 37 // Make sure we're really holding a reference to something inside the view38 assert(&result == &view.pred());39 }40 41 // Same, but calling on a non-const view42 {43 Pred pred{42};44 std::ranges::chunk_by_view<Range, Pred> view(Range{}, pred);45 std::same_as<Pred const&> decltype(auto) result = view.pred();46 assert(result.value == 42);47 48 // Make sure we're really holding a reference to something inside the view49 assert(&result == &view.pred());50 }51 52 return true;53}54 55int main(int, char**) {56 test();57 static_assert(test());58 59 return 0;60}61