| 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 | // template<class R, class Pred> |
| 12 | // take_while_view(R&&, Pred) -> take_while_view<views::all_t<R>, Pred>; |
| 13 | |
| 14 | #include <cassert> |
| 15 | #include <ranges> |
| 16 | #include <utility> |
| 17 | |
| 18 | #include "types.h" |
| 19 | |
| 20 | struct Container { |
| 21 | int* begin() const; |
| 22 | int* end() const; |
| 23 | }; |
| 24 | |
| 25 | struct View : std::ranges::view_base { |
| 26 | int* begin() const; |
| 27 | int* end() const; |
| 28 | }; |
| 29 | |
| 30 | struct Pred { |
| 31 | bool operator()(int i) const; |
| 32 | }; |
| 33 | |
| 34 | bool pred(int); |
| 35 | |
| 36 | static_assert(std::is_same_v<decltype(std::ranges::take_while_view(Container{}, Pred{})), |
| 37 | std::ranges::take_while_view<std::ranges::owning_view<Container>, Pred>>); |
| 38 | |
| 39 | static_assert(std::is_same_v<decltype(std::ranges::take_while_view(View{}, pred)), // |
| 40 | std::ranges::take_while_view<View, bool (*)(int)>>); |
| 41 | |
| 42 | static_assert(std::is_same_v<decltype(std::ranges::take_while_view(View{}, Pred{})), // |
| 43 | std::ranges::take_while_view<View, Pred>>); |
| 44 | |
| 45 | void testRef() { |
| 46 | Container c{}; |
| 47 | Pred p{}; |
| 48 | static_assert(std::is_same_v<decltype(std::ranges::take_while_view(c, p)), |
| 49 | std::ranges::take_while_view<std::ranges::ref_view<Container>, Pred>>); |
| 50 | } |
| 51 | |