]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/core/test/detail_iterator_test.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / core / test / detail_iterator_test.cpp
1 //
2 // Test for boost/detail/iterator.hpp
3 //
4 // Copyright 2014 Peter Dimov
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt
9 //
10
11 #define BOOST_ALLOW_DEPRECATED_HEADERS
12 #include <boost/detail/iterator.hpp>
13 #include <boost/core/is_same.hpp>
14 #include <boost/core/lightweight_test_trait.hpp>
15 #include <cstddef>
16 #include <list>
17
18 /*
19
20 namespace boost {
21 namespace detail {
22
23 template <class Iterator> struct iterator_traits: std::iterator_traits<Iterator>
24 {
25 };
26
27 using std::distance;
28
29 } // namespace detail
30 } // namespace boost
31
32 */
33
34 // struct C {} doesn't wotk with libc++.
35 typedef std::forward_iterator_tag C;
36
37 struct T
38 {
39 };
40
41 struct D
42 {
43 };
44
45 struct P
46 {
47 };
48
49 struct R
50 {
51 };
52
53 template< class Category, class T, class Distance = std::ptrdiff_t, class Pointer = T*, class Reference = T& >
54 struct iterator
55 {
56 typedef T value_type;
57 typedef Distance difference_type;
58 typedef Pointer pointer;
59 typedef Reference reference;
60 typedef Category iterator_category;
61 };
62
63 int main()
64 {
65 using boost::core::is_same;
66
67 /*
68 template<class Iterator> struct iterator_traits {
69 typedef typename Iterator::difference_type difference_type;
70 typedef typename Iterator::value_type value_type;
71 typedef typename Iterator::pointer pointer;
72 typedef typename Iterator::reference reference;
73 typedef typename Iterator::iterator_category iterator_category;
74 };
75 */
76 {
77 typedef ::iterator<C,T,D,P,R> It;
78
79 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::iterator_category,C>));
80 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::value_type,T>));
81 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::difference_type,D>));
82 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::pointer,P>));
83 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::reference,R>));
84 }
85 /*
86 template<class T> struct iterator_traits<T*> {
87 typedef ptrdiff_t difference_type;
88 typedef T value_type;
89 typedef T* pointer;
90 typedef T& reference;
91 typedef random_access_iterator_tag iterator_category;
92 };
93 */
94 {
95 typedef T* It;
96
97 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::iterator_category,std::random_access_iterator_tag>));
98 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::value_type,T>));
99 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::difference_type,std::ptrdiff_t>));
100 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::pointer,T*>));
101 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::reference,T&>));
102 }
103
104 /*
105 template<class T> struct iterator_traits<const T*> {
106 typedef ptrdiff_t difference_type;
107 typedef T value_type;
108 typedef const T* pointer;
109 typedef const T& reference;
110 typedef random_access_iterator_tag iterator_category;
111 };
112 */
113 {
114 typedef T const* It;
115
116 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::iterator_category,std::random_access_iterator_tag>));
117 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::value_type,T>));
118 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::difference_type,std::ptrdiff_t>));
119 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::pointer,T const*>));
120 BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::reference,T const&>));
121 }
122 /*
123 template<class InputIterator>
124 typename iterator_traits<InputIterator>::difference_type
125 distance( InputIterator first, InputIterator last );
126 */
127 {
128 int const N = 5;
129 T x[ N ] = {};
130
131 BOOST_TEST_EQ( boost::detail::distance( x, x + N ), N );
132 }
133
134 {
135 int const N = 5;
136 T const x[ N ] = {};
137
138 BOOST_TEST_EQ( boost::detail::distance( x, x + N ), N );
139 }
140
141 {
142 int const N = 5;
143 std::list<T> x( N );
144
145 BOOST_TEST_EQ( boost::detail::distance( x.begin(), x.end() ), x.size() );
146 }
147
148 return boost::report_errors();
149 }