| 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 explicit common_view(V r); |
| 12 |
|
| 13 |
#include <ranges> |
| 14 |
|
| 15 |
#include <cassert> |
| 16 |
#include <utility> |
| 17 |
|
| 18 |
#include "test_iterators.h" |
| 19 |
#include "types.h" |
| 20 |
|
| 21 |
constexpr bool test() { |
| 22 |
int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8}; |
| 23 |
|
| 24 |
{ |
| 25 |
MoveOnlyView view{buf, buf + 8}; |
| 26 |
std::ranges::common_view<MoveOnlyView> common(std::move(view)); |
| 27 |
assert(std::move(common).base().begin_ == buf); |
| 28 |
} |
| 29 |
|
| 30 |
{ |
| 31 |
CopyableView const view{buf, buf + 8}; |
| 32 |
std::ranges::common_view<CopyableView> const common(view); |
| 33 |
assert(common.base().begin_ == buf); |
| 34 |
} |
| 35 |
|
| 36 |
return true; |
| 37 |
} |
| 38 |
|
| 39 |
int main(int, char**) { |
| 40 |
test(); |
| 41 |
static_assert(test()); |
| 42 |
|
| 43 |
// Can't compare common_iterator inside constexpr |
| 44 |
{ |
| 45 |
int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8}; |
| 46 |
MoveOnlyView view{buf, buf + 8}; |
| 47 |
std::ranges::common_view<MoveOnlyView> const common(std::move(view)); |
| 48 |
assert(common.begin() == buf); |
| 49 |
} |
| 50 |
|
| 51 |
return 0; |
| 52 |
} |