| 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 iterator& operator++(); |
| 12 |
// constexpr void operator++(int); |
| 13 |
// constexpr iterator operator++(int) requires forward_range<Base>; |
| 14 |
|
| 15 |
#include <array> |
| 16 |
#include <cassert> |
| 17 |
#include <ranges> |
| 18 |
#include <tuple> |
| 19 |
|
| 20 |
#include "test_iterators.h" |
| 21 |
|
| 22 |
template <class Iter, class Sent = sentinel_wrapper<Iter>> |
| 23 |
constexpr void testOne() { |
| 24 |
using Range = std::ranges::subrange<Iter, Sent>; |
| 25 |
std::tuple<int> ts[] = {{1}, {2}, {3}}; |
| 26 |
auto ev = Range{Iter{&ts[0]}, Sent{Iter{&ts[0] + 3}}} | std::views::elements<0>; |
| 27 |
|
| 28 |
using ElementIter = std::ranges::iterator_t<decltype(ev)>; |
| 29 |
|
| 30 |
// ++i |
| 31 |
{ |
| 32 |
auto it = ev.begin(); |
| 33 |
decltype(auto) result = ++it; |
| 34 |
|
| 35 |
static_assert(std::is_same_v<decltype(result), ElementIter&>); |
| 36 |
assert(&result == &it); |
| 37 |
|
| 38 |
assert(base(it.base()) == &ts[1]); |
| 39 |
} |
| 40 |
|
| 41 |
// i++ |
| 42 |
{ |
| 43 |
if constexpr (std::forward_iterator<Iter>) { |
| 44 |
auto it = ev.begin(); |
| 45 |
decltype(auto) result = it++; |
| 46 |
|
| 47 |
static_assert(std::is_same_v<decltype(result), ElementIter>); |
| 48 |
|
| 49 |
assert(base(it.base()) == &ts[1]); |
| 50 |
assert(base(result.base()) == &ts[0]); |
| 51 |
} else { |
| 52 |
auto it = ev.begin(); |
| 53 |
it++; |
| 54 |
|
| 55 |
static_assert(std::is_same_v<decltype(it++), void>); |
| 56 |
assert(base(it.base()) == &ts[1]); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
constexpr bool test() { |
| 62 |
using Ptr = std::tuple<int>*; |
| 63 |
testOne<cpp20_input_iterator<Ptr>>(); |
| 64 |
testOne<forward_iterator<Ptr>>(); |
| 65 |
testOne<bidirectional_iterator<Ptr>>(); |
| 66 |
testOne<random_access_iterator<Ptr>>(); |
| 67 |
testOne<contiguous_iterator<Ptr>>(); |
| 68 |
testOne<Ptr>(); |
| 69 |
|
| 70 |
return true; |
| 71 |
} |
| 72 |
|
| 73 |
int main(int, char**) { |
| 74 |
test(); |
| 75 |
static_assert(test()); |
| 76 |
|
| 77 |
return 0; |
| 78 |
} |