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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14, c++17
10
11// constexpr explicit reverse_view(V r);
12
13#include <ranges>
14
15#include <cassert>
16#include <type_traits>
17#include <utility>
18
19#include "types.h"
20
21constexpr bool test() {
22 int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
23
24 {
25 BidirRange r{buffer, buffer + 8};
26 std::ranges::reverse_view<BidirRange> rev(r);
27 assert(rev.base().begin_ == buffer);
28 assert(rev.base().end_ == buffer + 8);
29 }
30 {
31 const BidirRange r{buffer, buffer + 8};
32 const std::ranges::reverse_view<BidirRange> rev(r);
33 assert(rev.base().begin_ == buffer);
34 assert(rev.base().end_ == buffer + 8);
35 }
36 {
37 std::ranges::reverse_view<BidirSentRange<MoveOnly>> rev(BidirSentRange<MoveOnly>{buffer, buffer + 8});
38 auto moved = std::move(rev).base();
39 assert(moved.begin_ == buffer);
40 assert(moved.end_ == buffer + 8);
41 }
42 {
43 const std::ranges::reverse_view<BidirSentRange<Copyable>> rev(BidirSentRange<Copyable>{buffer, buffer + 8});
44 assert(rev.base().begin_ == buffer);
45 assert(rev.base().end_ == buffer + 8);
46 }
47 {
48 // Make sure this ctor is marked as "explicit".
49 static_assert( std::is_constructible_v<std::ranges::reverse_view<BidirRange>, BidirRange>);
50 static_assert(!std::is_convertible_v<std::ranges::reverse_view<BidirRange>, BidirRange>);
51 }
52
53 return true;
54}
55
56int main(int, char**) {
57 test();
58 static_assert(test());
59
60 return 0;
61}
62

source code of libcxx/test/std/ranges/range.adaptors/range.reverse/ctor.view.pass.cpp