xref: /llvm-project/libcxx/test/std/ranges/range.adaptors/range.drop.while/pred.pass.cpp (revision 594fa1474f0c96da864257c0cda31b9b8381cd15)
1*594fa147SHui Xie //===----------------------------------------------------------------------===//
2*594fa147SHui Xie //
3*594fa147SHui Xie // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*594fa147SHui Xie // See https://llvm.org/LICENSE.txt for license information.
5*594fa147SHui Xie // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*594fa147SHui Xie //
7*594fa147SHui Xie //===----------------------------------------------------------------------===//
8*594fa147SHui Xie 
9*594fa147SHui Xie // UNSUPPORTED: c++03, c++11, c++14, c++17
10*594fa147SHui Xie 
11*594fa147SHui Xie // constexpr const Pred& pred() const;
12*594fa147SHui Xie 
13*594fa147SHui Xie #include <cassert>
14*594fa147SHui Xie #include <ranges>
15*594fa147SHui Xie #include <type_traits>
16*594fa147SHui Xie #include <utility>
17*594fa147SHui Xie 
18*594fa147SHui Xie struct View : std::ranges::view_interface<View> {
19*594fa147SHui Xie   int* begin() const;
20*594fa147SHui Xie   int* end() const;
21*594fa147SHui Xie };
22*594fa147SHui Xie 
23*594fa147SHui Xie struct Pred {
24*594fa147SHui Xie   int i;
25*594fa147SHui Xie   bool operator()(int) const;
26*594fa147SHui Xie };
27*594fa147SHui Xie 
test()28*594fa147SHui Xie constexpr bool test() {
29*594fa147SHui Xie   // &
30*594fa147SHui Xie   {
31*594fa147SHui Xie     std::ranges::drop_while_view<View, Pred> dwv{{}, Pred{5}};
32*594fa147SHui Xie     decltype(auto) x = dwv.pred();
33*594fa147SHui Xie     static_assert(std::same_as<decltype(x), Pred const&>);
34*594fa147SHui Xie     assert(x.i == 5);
35*594fa147SHui Xie   }
36*594fa147SHui Xie 
37*594fa147SHui Xie   // const &
38*594fa147SHui Xie   {
39*594fa147SHui Xie     const std::ranges::drop_while_view<View, Pred> dwv{{}, Pred{5}};
40*594fa147SHui Xie     decltype(auto) x = dwv.pred();
41*594fa147SHui Xie     static_assert(std::same_as<decltype(x), Pred const&>);
42*594fa147SHui Xie     assert(x.i == 5);
43*594fa147SHui Xie   }
44*594fa147SHui Xie 
45*594fa147SHui Xie   // &&
46*594fa147SHui Xie   {
47*594fa147SHui Xie     std::ranges::drop_while_view<View, Pred> dwv{{}, Pred{5}};
48*594fa147SHui Xie     decltype(auto) x = std::move(dwv).pred();
49*594fa147SHui Xie     static_assert(std::same_as<decltype(x), Pred const&>);
50*594fa147SHui Xie     assert(x.i == 5);
51*594fa147SHui Xie   }
52*594fa147SHui Xie 
53*594fa147SHui Xie   // const &&
54*594fa147SHui Xie   {
55*594fa147SHui Xie     const std::ranges::drop_while_view<View, Pred> dwv{{}, Pred{5}};
56*594fa147SHui Xie     decltype(auto) x = std::move(dwv).pred();
57*594fa147SHui Xie     static_assert(std::same_as<decltype(x), Pred const&>);
58*594fa147SHui Xie     assert(x.i == 5);
59*594fa147SHui Xie   }
60*594fa147SHui Xie 
61*594fa147SHui Xie   return true;
62*594fa147SHui Xie }
63*594fa147SHui Xie 
main(int,char **)64*594fa147SHui Xie int main(int, char**) {
65*594fa147SHui Xie   test();
66*594fa147SHui Xie   static_assert(test());
67*594fa147SHui Xie   return 0;
68*594fa147SHui Xie }
69