| 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 counted_iterator() requires default_initializable<I> = default; |
| 12 |
// constexpr counted_iterator(I x, iter_difference_t<I> n); |
| 13 |
// template<class I2> |
| 14 |
// requires convertible_to<const I2&, I> |
| 15 |
// constexpr counted_iterator(const counted_iterator<I2>& x); |
| 16 |
|
| 17 |
#include <iterator> |
| 18 |
|
| 19 |
#include "test_macros.h" |
| 20 |
#include "test_iterators.h" |
| 21 |
|
| 22 |
struct InputOrOutputArchetype { |
| 23 |
using difference_type = int; |
| 24 |
|
| 25 |
int *ptr; |
| 26 |
|
| 27 |
constexpr int operator*() { return *ptr; } |
| 28 |
constexpr void operator++(int) { ++ptr; } |
| 29 |
constexpr InputOrOutputArchetype& operator++() { ++ptr; return *this; } |
| 30 |
}; |
| 31 |
|
| 32 |
constexpr bool test() { |
| 33 |
int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8}; |
| 34 |
|
| 35 |
{ |
| 36 |
std::counted_iterator iter(cpp20_input_iterator<int*>{buffer}, 8); |
| 37 |
assert(base(iter.base()) == buffer); |
| 38 |
assert(iter.count() == 8); |
| 39 |
} |
| 40 |
|
| 41 |
{ |
| 42 |
std::counted_iterator iter(forward_iterator<int*>{buffer}, 8); |
| 43 |
assert(iter.base() == forward_iterator<int*>{buffer}); |
| 44 |
assert(iter.count() == 8); |
| 45 |
} |
| 46 |
|
| 47 |
{ |
| 48 |
std::counted_iterator iter(contiguous_iterator<int*>{buffer}, 8); |
| 49 |
assert(iter.base() == contiguous_iterator<int*>{buffer}); |
| 50 |
assert(iter.count() == 8); |
| 51 |
} |
| 52 |
|
| 53 |
{ |
| 54 |
std::counted_iterator iter(InputOrOutputArchetype{buffer}, 8); |
| 55 |
assert(iter.base().ptr == buffer); |
| 56 |
assert(iter.count() == 8); |
| 57 |
} |
| 58 |
|
| 59 |
return true; |
| 60 |
} |
| 61 |
|
| 62 |
int main(int, char**) { |
| 63 |
test(); |
| 64 |
static_assert(test()); |
| 65 |
|
| 66 |
return 0; |
| 67 |
} |