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// <iterator>
10
11// template<class Iter>
12// struct iterator_traits
13// {
14// typedef typename Iter::difference_type difference_type;
15// typedef typename Iter::value_type value_type;
16// typedef typename Iter::pointer pointer;
17// typedef typename Iter::reference reference;
18// typedef typename Iter::iterator_category iterator_category;
19// };
20
21#include <iterator>
22#include <type_traits>
23
24#include "test_macros.h"
25
26struct A {};
27
28struct test_iterator
29{
30 typedef int difference_type;
31 typedef A value_type;
32 typedef A* pointer;
33 typedef A& reference;
34 typedef std::forward_iterator_tag iterator_category;
35};
36
37int main(int, char**)
38{
39 typedef std::iterator_traits<test_iterator> It;
40 static_assert((std::is_same<It::difference_type, int>::value), "");
41 static_assert((std::is_same<It::value_type, A>::value), "");
42 static_assert((std::is_same<It::pointer, A*>::value), "");
43 static_assert((std::is_same<It::reference, A&>::value), "");
44 static_assert((std::is_same<It::iterator_category, std::forward_iterator_tag>::value), "");
45
46 return 0;
47}
48

source code of libcxx/test/std/iterators/iterator.primitives/iterator.traits/iterator.pass.cpp