| 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 outer-iterator& outer-iterator::operator++(); |
| 12 |
// constexpr decltype(auto) outer-iterator::operator++(int); |
| 13 |
|
| 14 |
// Note that corner cases are tested in `range.lazy.split/general.pass.cpp`. |
| 15 |
|
| 16 |
#include <ranges> |
| 17 |
|
| 18 |
#include <algorithm> |
| 19 |
#include <cassert> |
| 20 |
#include <string> |
| 21 |
#include "../types.h" |
| 22 |
|
| 23 |
constexpr bool test() { |
| 24 |
using namespace std::string_literals; |
| 25 |
// Can call `outer-iterator::operator++`; `View` is a forward range. |
| 26 |
{ |
| 27 |
SplitViewForward v("abc def ghi", " "); |
| 28 |
|
| 29 |
// ++i |
| 30 |
{ |
| 31 |
auto i = v.begin(); |
| 32 |
assert(std::ranges::equal(*i, "abc"s)); |
| 33 |
|
| 34 |
decltype(auto) i2 = ++i; |
| 35 |
static_assert(std::is_lvalue_reference_v<decltype(i2)>); |
| 36 |
assert(&i2 == &i); |
| 37 |
assert(std::ranges::equal(*i2, "def"s)); |
| 38 |
} |
| 39 |
|
| 40 |
// i++ |
| 41 |
{ |
| 42 |
auto i = v.begin(); |
| 43 |
assert(std::ranges::equal(*i, "abc"s)); |
| 44 |
|
| 45 |
decltype(auto) i2 = i++; |
| 46 |
static_assert(!std::is_reference_v<decltype(i2)>); |
| 47 |
assert(std::ranges::equal(*i2, "abc"s)); |
| 48 |
assert(std::ranges::equal(*i, "def"s)); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
// Can call `outer-iterator::operator++`; `View` is an input range. |
| 53 |
{ |
| 54 |
SplitViewInput v("abc def ghi", ' '); |
| 55 |
|
| 56 |
// ++i |
| 57 |
{ |
| 58 |
auto i = v.begin(); |
| 59 |
assert(std::ranges::equal(*i, "abc"s)); |
| 60 |
|
| 61 |
decltype(auto) i2 = ++i; |
| 62 |
static_assert(std::is_lvalue_reference_v<decltype(i2)>); |
| 63 |
assert(&i2 == &i); |
| 64 |
assert(std::ranges::equal(*i2, "def"s)); |
| 65 |
} |
| 66 |
|
| 67 |
// i++ |
| 68 |
{ |
| 69 |
auto i = v.begin(); |
| 70 |
assert(std::ranges::equal(*i, "abc"s)); |
| 71 |
|
| 72 |
static_assert(std::is_void_v<decltype(i++)>); |
| 73 |
i++; |
| 74 |
assert(std::ranges::equal(*i, "def"s)); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
return true; |
| 79 |
} |
| 80 |
|
| 81 |
int main(int, char**) { |
| 82 |
test(); |
| 83 |
static_assert(test()); |
| 84 |
|
| 85 |
return 0; |
| 86 |
} |