| 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 <cassert> |
| 15 |
#include <ranges> |
| 16 |
#include <type_traits> |
| 17 |
#include <utility> |
| 18 |
|
| 19 |
#include "MoveOnly.h" |
| 20 |
|
| 21 |
struct View : std::ranges::view_base { |
| 22 |
int i; |
| 23 |
int* begin() const; |
| 24 |
int* end() const; |
| 25 |
}; |
| 26 |
|
| 27 |
struct MoveOnlyView : View { |
| 28 |
MoveOnly mo; |
| 29 |
}; |
| 30 |
|
| 31 |
template <class T> |
| 32 |
concept HasBase = requires(T&& t) { std::forward<T>(t).base(); }; |
| 33 |
|
| 34 |
struct Pred { |
| 35 |
constexpr bool operator()(int i) const { return i > 5; } |
| 36 |
}; |
| 37 |
|
| 38 |
static_assert(HasBase<std::ranges::drop_while_view<View, Pred> const&>); |
| 39 |
static_assert(HasBase<std::ranges::drop_while_view<View, Pred>&&>); |
| 40 |
|
| 41 |
static_assert(!HasBase<std::ranges::drop_while_view<MoveOnlyView, Pred> const&>); |
| 42 |
static_assert(HasBase<std::ranges::drop_while_view<MoveOnlyView, Pred>&&>); |
| 43 |
|
| 44 |
constexpr bool test() { |
| 45 |
// const & |
| 46 |
{ |
| 47 |
const std::ranges::drop_while_view<View, Pred> dwv{View{{}, 5}, {}}; |
| 48 |
std::same_as<View> decltype(auto) v = dwv.base(); |
| 49 |
assert(v.i == 5); |
| 50 |
} |
| 51 |
|
| 52 |
// & |
| 53 |
{ |
| 54 |
std::ranges::drop_while_view<View, Pred> dwv{View{{}, 5}, {}}; |
| 55 |
std::same_as<View> decltype(auto) v = dwv.base(); |
| 56 |
assert(v.i == 5); |
| 57 |
} |
| 58 |
|
| 59 |
// && |
| 60 |
{ |
| 61 |
std::ranges::drop_while_view<View, Pred> dwv{View{{}, 5}, {}}; |
| 62 |
std::same_as<View> decltype(auto) v = std::move(dwv).base(); |
| 63 |
assert(v.i == 5); |
| 64 |
} |
| 65 |
|
| 66 |
// const && |
| 67 |
{ |
| 68 |
const std::ranges::drop_while_view<View, Pred> dwv{View{{}, 5}, {}}; |
| 69 |
std::same_as<View> decltype(auto) v = std::move(dwv).base(); |
| 70 |
assert(v.i == 5); |
| 71 |
} |
| 72 |
|
| 73 |
// move only |
| 74 |
{ |
| 75 |
std::ranges::drop_while_view<MoveOnlyView, Pred> dwv{MoveOnlyView{{}, 5}, {}}; |
| 76 |
std::same_as<MoveOnlyView> decltype(auto) v = std::move(dwv).base(); |
| 77 |
assert(v.mo.get() == 5); |
| 78 |
} |
| 79 |
return true; |
| 80 |
} |
| 81 |
|
| 82 |
int main(int, char**) { |
| 83 |
test(); |
| 84 |
static_assert(test()); |
| 85 |
return 0; |
| 86 |
} |