brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · a3ddbf8 Raw
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++1710 11// constexpr iterator<false> begin();12// constexpr iterator<true> begin() const13//   requires range<const V> &&14//            regular_invocable<const F&, range_reference_t<const V>>;15 16#include <ranges>17 18#include "test_macros.h"19#include "types.h"20 21template<class T>22concept BeginInvocable = requires(T t) { t.begin(); };23 24constexpr bool test() {25  int buff[8] = {0, 1, 2, 3, 4, 5, 6, 7};26 27  {28    std::ranges::transform_view transformView(MoveOnlyView{buff}, PlusOneMutable{});29    assert(transformView.begin().base() == buff);30    assert(*transformView.begin() == 1);31  }32 33  {34    std::ranges::transform_view transformView(ForwardView{buff}, PlusOneMutable{});35    assert(base(transformView.begin().base()) == buff);36    assert(*transformView.begin() == 1);37  }38 39  {40    std::ranges::transform_view transformView(InputView{buff}, PlusOneMutable{});41    assert(base(transformView.begin().base()) == buff);42    assert(*transformView.begin() == 1);43  }44 45  {46    const std::ranges::transform_view transformView(MoveOnlyView{buff}, PlusOne{});47    assert(*transformView.begin() == 1);48  }49 50  static_assert(!BeginInvocable<const std::ranges::transform_view<MoveOnlyView, PlusOneMutable>>);51 52  return true;53}54 55int main(int, char**) {56  test();57  static_assert(test());58 59  return 0;60}61