brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 9df2928 Raw
71 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// template <class Range, class Pred>14// chunk_by_view(Range&&, Pred) -> chunk_by_view<views::all_t<Range>, Pred>;15 16#include <ranges>17 18#include <cassert>19#include <type_traits>20 21#include "test_iterators.h"22 23struct View : std::ranges::view_base {24  View() = default;25  forward_iterator<int*> begin() const;26  sentinel_wrapper<forward_iterator<int*>> end() const;27};28static_assert(std::ranges::view<View>);29 30// A range that is not a view31struct Range {32  Range() = default;33  forward_iterator<int*> begin() const;34  sentinel_wrapper<forward_iterator<int*>> end() const;35};36static_assert(std::ranges::range<Range>);37static_assert(!std::ranges::view<Range>);38 39struct Pred {40  constexpr bool operator()(int x, int y) const { return x <= y; }41};42 43constexpr bool test() {44  {45    View v;46    Pred pred;47    std::ranges::chunk_by_view view(v, pred);48    static_assert(std::is_same_v<decltype(view), std::ranges::chunk_by_view<View, Pred>>);49  }50  {51    Range r;52    Pred pred;53    std::ranges::chunk_by_view view(r, pred);54    static_assert(std::is_same_v<decltype(view), std::ranges::chunk_by_view<std::ranges::ref_view<Range>, Pred>>);55  }56  {57    Pred pred;58    std::ranges::chunk_by_view view(Range{}, pred);59    static_assert(std::is_same_v<decltype(view), std::ranges::chunk_by_view<std::ranges::owning_view<Range>, Pred>>);60  }61 62  return true;63}64 65int main(int, char**) {66  test();67  static_assert(test());68 69  return 0;70}71