brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · e6c7094 Raw
148 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// constexpr auto end()12// constexpr auto end() const13//   requires range<const InnerView> &&14//            regular_invocable<const F&, range_reference_t<const Views>...>;15 16#include <ranges>17 18#include "types.h"19 20template <class T>21concept HasConstEnd = requires(const T& ct) { ct.end(); };22 23template <class T>24concept HasEnd = requires(T& t) { t.end(); };25 26constexpr bool test() {27  int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};28  {29    // simple test30    std::ranges::zip_transform_view v(31        MakeTuple{}, SimpleCommon{buffer}, std::views::iota(0), std::ranges::single_view(2.));32    assert(v.begin() != v.end());33    assert(std::as_const(v).begin() != std::as_const(v).end());34    assert(v.begin() + 1 == v.end());35    assert(std::as_const(v).begin() + 1 == std::as_const(v).end());36  }37 38  {39    // one range40    std::ranges::zip_transform_view v(MakeTuple{}, SimpleCommon{buffer});41    auto it = v.begin();42    assert(it + 8 == v.end());43    assert(it + 8 == std::as_const(v).end());44  }45 46  {47    // two ranges48    std::ranges::zip_transform_view v(GetFirst{}, SimpleCommon{buffer}, std::views::iota(0));49    auto it = v.begin();50    assert(it + 8 == v.end());51    assert(it + 8 == std::as_const(v).end());52  }53 54  {55    // three ranges56    std::ranges::zip_transform_view v(Tie{}, SimpleCommon{buffer}, SimpleCommon{buffer}, std::ranges::single_view(2.));57    auto it = v.begin();58    assert(it + 1 == v.end());59    assert(it + 1 == std::as_const(v).end());60  }61 62  {63    // single empty range64    std::ranges::zip_transform_view v(MakeTuple{}, std::ranges::empty_view<int>());65    assert(v.begin() == v.end());66    assert(std::as_const(v).begin() == std::as_const(v).end());67  }68 69  {70    // empty range at the beginning71    std::ranges::zip_transform_view v(72        MakeTuple{}, std::ranges::empty_view<int>(), SimpleCommon{buffer}, SimpleCommon{buffer});73    assert(v.begin() == v.end());74    assert(std::as_const(v).begin() == std::as_const(v).end());75  }76 77  {78    // empty range in the middle79    std::ranges::zip_transform_view v(80        MakeTuple{}, SimpleCommon{buffer}, std::ranges::empty_view<int>(), SimpleCommon{buffer});81    assert(v.begin() == v.end());82    assert(std::as_const(v).begin() == std::as_const(v).end());83  }84 85  {86    // empty range at the end87    std::ranges::zip_transform_view v(88        MakeTuple{}, SimpleCommon{buffer}, SimpleCommon{buffer}, std::ranges::empty_view<int>());89    assert(v.begin() == v.end());90    assert(std::as_const(v).begin() == std::as_const(v).end());91  }92 93  {94    // common_range<InnerView>95    std::ranges::zip_transform_view v(MakeTuple{}, SimpleCommon{buffer});96    auto it       = v.begin();97    auto const_it = std::as_const(v).begin();98    auto st       = v.end();99    auto const_st = std::as_const(v).end();100 101    static_assert(!std::same_as<decltype(it), decltype(const_it)>);102    static_assert(!std::same_as<decltype(st), decltype(const_st)>);103    static_assert(std::same_as<decltype(it), decltype(st)>);104    static_assert(std::same_as<decltype(const_it), decltype(const_st)>);105 106    assert(it + 8 == st);107    assert(const_it + 8 == const_st);108  }109  {110    // !common_range<InnerView>111    std::ranges::zip_transform_view v(MakeTuple{}, SimpleNonCommon{buffer});112    auto it       = v.begin();113    auto const_it = std::as_const(v).begin();114    auto st       = v.end();115    auto const_st = std::as_const(v).end();116 117    static_assert(!std::same_as<decltype(it), decltype(const_it)>);118    static_assert(!std::same_as<decltype(st), decltype(const_st)>);119    static_assert(!std::same_as<decltype(it), decltype(st)>);120    static_assert(!std::same_as<decltype(const_it), decltype(const_st)>);121 122    assert(it + 8 == st);123    assert(const_it + 8 == const_st);124  }125 126  {127    // underlying const R is not a range128    using ZTV = std::ranges::zip_transform_view<MakeTuple, SimpleCommon, NoConstBeginView>;129    static_assert(HasEnd<ZTV>);130    static_assert(!HasConstEnd<ZTV>);131  }132 133  {134    // Fn cannot invoke on const range135    using ZTV = std::ranges::zip_transform_view<NonConstOnlyFn, ConstNonConstDifferentView>;136    static_assert(HasEnd<ZTV>);137    static_assert(!HasConstEnd<ZTV>);138  }139  return true;140}141 142int main(int, char**) {143  test();144  static_assert(test());145 146  return 0;147}148