brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 1a0a5ab Raw
69 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 V base() const& requires copy_constructible<V>;12// constexpr V base() &&;13 14#include <ranges>15 16#include <cassert>17#include <utility>18 19#include "test_macros.h"20#include "types.h"21 22constexpr bool hasLValueQualifiedBase(auto&& view) {23  return requires { view.base(); };24}25 26constexpr bool test() {27  int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};28 29  {30    CopyableView view{buf, buf + 8};31    std::ranges::common_view<CopyableView> common(view);32    assert(common.base().begin_ == buf);33    assert(std::move(common).base().begin_ == buf);34 35    ASSERT_SAME_TYPE(decltype(common.base()), CopyableView);36    ASSERT_SAME_TYPE(decltype(std::move(common).base()), CopyableView);37    static_assert(hasLValueQualifiedBase(common));38  }39 40  {41    MoveOnlyView view{buf, buf + 8};42    std::ranges::common_view<MoveOnlyView> common(std::move(view));43    assert(std::move(common).base().begin_ == buf);44 45    ASSERT_SAME_TYPE(decltype(std::move(common).base()), MoveOnlyView);46    static_assert(!hasLValueQualifiedBase(common));47  }48 49  {50    CopyableView view{buf, buf + 8};51    const std::ranges::common_view<CopyableView> common(view);52    assert(common.base().begin_ == buf);53    assert(std::move(common).base().begin_ == buf);54 55    ASSERT_SAME_TYPE(decltype(common.base()), CopyableView);56    ASSERT_SAME_TYPE(decltype(std::move(common).base()), CopyableView);57    static_assert(hasLValueQualifiedBase(common));58  }59 60  return true;61}62 63int main(int, char**) {64  test();65  static_assert(test());66 67  return 0;68}69