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 V base() const& requires copy_constructible<V> { return base_; } |
12 | // constexpr V base() && { return std::move(base_); } |
13 | |
14 | #include <ranges> |
15 | |
16 | #include <cassert> |
17 | #include <concepts> |
18 | |
19 | #include "types.h" |
20 | |
21 | constexpr bool test() { |
22 | int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8}; |
23 | |
24 | // Test common ranges. |
25 | { |
26 | // Test non-const. |
27 | { |
28 | auto rev = std::ranges::reverse_view(BidirRange{buffer, buffer + 8}); |
29 | |
30 | std::same_as<BidirRange> auto base = rev.base(); |
31 | assert(base.begin_ == buffer); |
32 | assert(base.end_ == buffer + 8); |
33 | |
34 | std::same_as<BidirRange> auto moved = std::move(rev).base(); |
35 | assert(moved.begin_ == buffer); |
36 | assert(moved.end_ == buffer + 8); |
37 | } |
38 | // Test const. |
39 | { |
40 | const auto rev = std::ranges::reverse_view(BidirRange{buffer, buffer + 8}); |
41 | |
42 | std::same_as<BidirRange> auto base = rev.base(); |
43 | assert(base.begin_ == buffer); |
44 | assert(base.end_ == buffer + 8); |
45 | |
46 | std::same_as<BidirRange> auto moved = std::move(rev).base(); |
47 | assert(moved.begin_ == buffer); |
48 | assert(moved.end_ == buffer + 8); |
49 | } |
50 | } |
51 | // Test non-common ranges. |
52 | { |
53 | // Test non-const (also move only). |
54 | { |
55 | auto rev = std::ranges::reverse_view(BidirSentRange<MoveOnly>{buffer, buffer + 8}); |
56 | std::same_as<BidirSentRange<MoveOnly>> auto base = std::move(rev).base(); |
57 | assert(base.begin_ == buffer); |
58 | assert(base.end_ == buffer + 8); |
59 | } |
60 | // Test const. |
61 | { |
62 | const auto rev = std::ranges::reverse_view(BidirSentRange<Copyable>{buffer, buffer + 8}); |
63 | |
64 | std::same_as<BidirSentRange<Copyable>> auto base = rev.base(); |
65 | assert(base.begin_ == buffer); |
66 | assert(base.end_ == buffer + 8); |
67 | |
68 | std::same_as<BidirSentRange<Copyable>> auto moved = std::move(rev).base(); |
69 | assert(moved.begin_ == buffer); |
70 | assert(moved.end_ == buffer + 8); |
71 | } |
72 | } |
73 | |
74 | return true; |
75 | } |
76 | |
77 | int main(int, char**) { |
78 | test(); |
79 | static_assert(test()); |
80 | |
81 | return 0; |
82 | } |
83 | |