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 const Pred& pred() const; |
12 | |
13 | #include <cassert> |
14 | #include <ranges> |
15 | #include <type_traits> |
16 | #include <utility> |
17 | |
18 | struct View : std::ranges::view_interface<View> { |
19 | int* begin() const; |
20 | int* end() const; |
21 | }; |
22 | |
23 | struct Pred { |
24 | int i; |
25 | bool operator()(int) const; |
26 | }; |
27 | |
28 | constexpr bool test() { |
29 | // & |
30 | { |
31 | std::ranges::drop_while_view<View, Pred> dwv{{}, Pred{5}}; |
32 | decltype(auto) x = dwv.pred(); |
33 | static_assert(std::same_as<decltype(x), Pred const&>); |
34 | assert(x.i == 5); |
35 | } |
36 | |
37 | // const & |
38 | { |
39 | const std::ranges::drop_while_view<View, Pred> dwv{{}, Pred{5}}; |
40 | decltype(auto) x = dwv.pred(); |
41 | static_assert(std::same_as<decltype(x), Pred const&>); |
42 | assert(x.i == 5); |
43 | } |
44 | |
45 | // && |
46 | { |
47 | std::ranges::drop_while_view<View, Pred> dwv{{}, Pred{5}}; |
48 | decltype(auto) x = std::move(dwv).pred(); |
49 | static_assert(std::same_as<decltype(x), Pred const&>); |
50 | assert(x.i == 5); |
51 | } |
52 | |
53 | // const && |
54 | { |
55 | const std::ranges::drop_while_view<View, Pred> dwv{{}, Pred{5}}; |
56 | decltype(auto) x = std::move(dwv).pred(); |
57 | static_assert(std::same_as<decltype(x), Pred const&>); |
58 | assert(x.i == 5); |
59 | } |
60 | |
61 | return true; |
62 | } |
63 | |
64 | int main(int, char**) { |
65 | test(); |
66 | static_assert(test()); |
67 | return 0; |
68 | } |
69 | |