1594fa147SHui Xie //===----------------------------------------------------------------------===//
2594fa147SHui Xie //
3594fa147SHui Xie // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4594fa147SHui Xie // See https://llvm.org/LICENSE.txt for license information.
5594fa147SHui Xie // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6594fa147SHui Xie //
7594fa147SHui Xie //===----------------------------------------------------------------------===//
8594fa147SHui Xie
9594fa147SHui Xie // UNSUPPORTED: c++03, c++11, c++14, c++17
10594fa147SHui Xie
11*40aaa272SHristo Hristov // constexpr drop_while_view(V base, Pred pred); // explicit since C++23
12594fa147SHui Xie
13594fa147SHui Xie #include <cassert>
14594fa147SHui Xie #include <ranges>
15594fa147SHui Xie #include <type_traits>
16594fa147SHui Xie #include <utility>
17594fa147SHui Xie
18594fa147SHui Xie #include "MoveOnly.h"
19*40aaa272SHristo Hristov #include "test_convertible.h"
20*40aaa272SHristo Hristov #include "test_macros.h"
21594fa147SHui Xie
22594fa147SHui Xie struct View : std::ranges::view_base {
23594fa147SHui Xie MoveOnly mo;
24594fa147SHui Xie int* begin() const;
25594fa147SHui Xie int* end() const;
26594fa147SHui Xie };
27594fa147SHui Xie
28594fa147SHui Xie struct Pred {
29594fa147SHui Xie bool copied = false;
30594fa147SHui Xie bool moved = false;
31594fa147SHui Xie constexpr Pred() = default;
PredPred32594fa147SHui Xie constexpr Pred(Pred&&) : moved(true) {}
PredPred33594fa147SHui Xie constexpr Pred(const Pred&) : copied(true) {}
34594fa147SHui Xie bool operator()(int) const;
35594fa147SHui Xie };
36594fa147SHui Xie
37*40aaa272SHristo Hristov // SFINAE tests.
38*40aaa272SHristo Hristov
39*40aaa272SHristo Hristov #if TEST_STD_VER >= 23
40*40aaa272SHristo Hristov
41*40aaa272SHristo Hristov static_assert(!test_convertible<std::ranges::drop_while_view<View, Pred>, View, Pred>(),
42*40aaa272SHristo Hristov "This constructor must be explicit");
43*40aaa272SHristo Hristov
44*40aaa272SHristo Hristov #else
45*40aaa272SHristo Hristov
46*40aaa272SHristo Hristov static_assert( test_convertible<std::ranges::drop_while_view<View, Pred>, View, Pred>(),
47*40aaa272SHristo Hristov "This constructor must not be explicit");
48*40aaa272SHristo Hristov
49*40aaa272SHristo Hristov #endif // TEST_STD_VER >= 23
50*40aaa272SHristo Hristov
test()51594fa147SHui Xie constexpr bool test() {
52594fa147SHui Xie {
53*40aaa272SHristo Hristov std::ranges::drop_while_view<View, Pred> dwv{View{{}, MoveOnly{5}}, Pred{}};
54594fa147SHui Xie assert(dwv.pred().moved);
55594fa147SHui Xie assert(!dwv.pred().copied);
56594fa147SHui Xie assert(std::move(dwv).base().mo.get() == 5);
57594fa147SHui Xie }
58594fa147SHui Xie return true;
59594fa147SHui Xie }
60594fa147SHui Xie
main(int,char **)61594fa147SHui Xie int main(int, char**) {
62594fa147SHui Xie test();
63594fa147SHui Xie static_assert(test());
64*40aaa272SHristo Hristov
65594fa147SHui Xie return 0;
66594fa147SHui Xie }
67