Files
carbon-lang/libcxx/test/std/ranges/range.adaptors/range.common.view/ctad.compile.pass.cpp
T
Mark de Wever 71909de374 [libc++] Disable incomplete library features.
Adds a new CMake option to disable the usage of incomplete headers.
These incomplete headers are not guaranteed to be ABI stable. This
option is intended to be used by vendors so they can avoid their users
from code that's not ready for production usage.

The option is enabled by default.

Differential Revision: https://reviews.llvm.org/D106763
2021-07-27 22:37:35 +02:00

69 lines
2.1 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-no-concepts
// UNSUPPORTED: gcc-10
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
// template<class R>
// common_view(R&&) -> common_view<views::all_t<R>>;
#include <ranges>
#include <cassert>
#include "test_iterators.h"
struct View : std::ranges::view_base {
friend int* begin(View&);
friend int* begin(View const&);
friend sentinel_wrapper<int*> end(View&);
friend sentinel_wrapper<int*> end(View const&);
};
struct Range {
friend int* begin(Range&);
friend int* begin(Range const&);
friend sentinel_wrapper<int*> end(Range&);
friend sentinel_wrapper<int*> end(Range const&);
};
struct BorrowedRange {
friend int* begin(BorrowedRange&);
friend int* begin(BorrowedRange const&);
friend sentinel_wrapper<int*> end(BorrowedRange&);
friend sentinel_wrapper<int*> end(BorrowedRange const&);
};
template<>
inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true;
void testCTAD() {
View v;
Range r;
BorrowedRange br;
static_assert(std::same_as<
decltype(std::ranges::common_view(v)),
std::ranges::common_view<View>
>);
static_assert(std::same_as<
decltype(std::ranges::common_view(r)),
std::ranges::common_view<std::ranges::ref_view<Range>>
>);
// std::ranges::common_view(std::move(r)) invalid. RValue range must be borrowed.
static_assert(std::same_as<
decltype(std::ranges::common_view(br)),
std::ranges::common_view<std::ranges::ref_view<BorrowedRange>>
>);
static_assert(std::same_as<
decltype(std::ranges::common_view(std::move(br))),
std::ranges::common_view<std::ranges::subrange<
int *, sentinel_wrapper<int *>, std::ranges::subrange_kind::unsized>>
>);
}