83 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// template<class R>12// explicit join_view(R&&) -> join_view<views::all_t<R>>;13 14#include <ranges>15#include <utility>16 17struct Child {18 int *begin() const;19 int *end() const;20};21 22struct View : std::ranges::view_base {23 Child *begin() const;24 Child *end() const;25};26 27struct Range {28 Child *begin() const;29 Child *end() const;30};31 32struct BorrowedRange {33 Child *begin() const;34 Child *end() const;35};36template<>37inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true;38 39struct NestedChildren : std::ranges::view_base {40 View* begin() const;41 View* end() const;42};43 44void testCTAD() {45 View v;46 Range r;47 BorrowedRange br;48 49 static_assert(std::same_as<50 decltype(std::ranges::join_view(v)),51 std::ranges::join_view<View>52 >);53 static_assert(std::same_as<54 decltype(std::ranges::join_view(std::move(v))),55 std::ranges::join_view<View>56 >);57 static_assert(std::same_as<58 decltype(std::ranges::join_view(r)),59 std::ranges::join_view<std::ranges::ref_view<Range>>60 >);61 static_assert(std::same_as<62 decltype(std::ranges::join_view(std::move(r))),63 std::ranges::join_view<std::ranges::owning_view<Range>>64 >);65 static_assert(std::same_as<66 decltype(std::ranges::join_view(br)),67 std::ranges::join_view<std::ranges::ref_view<BorrowedRange>>68 >);69 static_assert(std::same_as<70 decltype(std::ranges::join_view(std::move(br))),71 std::ranges::join_view<std::ranges::owning_view<BorrowedRange>>72 >);73 74 NestedChildren n;75 std::ranges::join_view jv(n);76 77 // CTAD generated from the copy constructor instead of joining the join_view78 static_assert(std::same_as< decltype(std::ranges::join_view(jv)), decltype(jv) >);79 80 // CTAD generated from the move constructor instead of joining the join_view81 static_assert(std::same_as< decltype(std::ranges::join_view(std::move(jv))), decltype(jv) >);82}83