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// template<input_iterator I>
12// requires same_as<ITER_TRAITS(I), iterator_traits<I>> // see [iterator.concepts.general]
13// struct iterator_traits<counted_iterator<I>> : iterator_traits<I> {
14// using pointer = conditional_t<contiguous_iterator<I>,
15// add_pointer_t<iter_reference_t<I>>, void>;
16// };
17
18#include <iterator>
19
20#include "test_macros.h"
21#include "test_iterators.h"
22
23void test() {
24 {
25 using Iter = cpp17_input_iterator<int*>;
26 using CommonIter = std::counted_iterator<Iter>;
27 using IterTraits = std::iterator_traits<CommonIter>;
28
29 static_assert(std::same_as<IterTraits::iterator_category, std::input_iterator_tag>);
30 static_assert(std::same_as<IterTraits::value_type, int>);
31 static_assert(std::same_as<IterTraits::difference_type, std::ptrdiff_t>);
32 static_assert(std::same_as<IterTraits::pointer, void>);
33 static_assert(std::same_as<IterTraits::reference, int&>);
34 }
35 {
36 using Iter = forward_iterator<int*>;
37 using CommonIter = std::counted_iterator<Iter>;
38 using IterTraits = std::iterator_traits<CommonIter>;
39
40 static_assert(std::same_as<IterTraits::iterator_category, std::forward_iterator_tag>);
41 static_assert(std::same_as<IterTraits::value_type, int>);
42 static_assert(std::same_as<IterTraits::difference_type, std::ptrdiff_t>);
43 static_assert(std::same_as<IterTraits::pointer, void>);
44 static_assert(std::same_as<IterTraits::reference, int&>);
45 }
46 {
47 using Iter = random_access_iterator<int*>;
48 using CommonIter = std::counted_iterator<Iter>;
49 using IterTraits = std::iterator_traits<CommonIter>;
50
51 static_assert(std::same_as<IterTraits::iterator_category, std::random_access_iterator_tag>);
52 static_assert(std::same_as<IterTraits::value_type, int>);
53 static_assert(std::same_as<IterTraits::difference_type, std::ptrdiff_t>);
54 static_assert(std::same_as<IterTraits::pointer, void>);
55 static_assert(std::same_as<IterTraits::reference, int&>);
56 }
57 {
58 using Iter = contiguous_iterator<int*>;
59 using CommonIter = std::counted_iterator<Iter>;
60 using IterTraits = std::iterator_traits<CommonIter>;
61
62 static_assert(std::same_as<IterTraits::iterator_category, std::contiguous_iterator_tag>);
63 static_assert(std::same_as<IterTraits::value_type, int>);
64 static_assert(std::same_as<IterTraits::difference_type, std::ptrdiff_t>);
65 static_assert(std::same_as<IterTraits::pointer, int*>);
66 static_assert(std::same_as<IterTraits::reference, int&>);
67 }
68}
69

source code of libcxx/test/std/iterators/predef.iterators/counted.iterator/iterator_traits.compile.pass.cpp