2 // Test for boost/detail/iterator.hpp
4 // Copyright 2014 Peter Dimov
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
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>
23 template <class Iterator> struct iterator_traits: std::iterator_traits<Iterator>
34 // struct C {} doesn't wotk with libc++.
35 typedef std::forward_iterator_tag C
;
53 template< class Category
, class T
, class Distance
= std::ptrdiff_t, class Pointer
= T
*, class Reference
= T
& >
57 typedef Distance difference_type
;
58 typedef Pointer pointer
;
59 typedef Reference reference
;
60 typedef Category iterator_category
;
65 using boost::core::is_same
;
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;
77 typedef ::iterator
<C
,T
,D
,P
,R
> It
;
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
>));
86 template<class T> struct iterator_traits<T*> {
87 typedef ptrdiff_t difference_type;
91 typedef random_access_iterator_tag iterator_category;
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
&>));
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;
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&>));
123 template<class InputIterator>
124 typename iterator_traits<InputIterator>::difference_type
125 distance( InputIterator first, InputIterator last );
131 BOOST_TEST_EQ( boost::detail::distance( x
, x
+ N
), N
);
138 BOOST_TEST_EQ( boost::detail::distance( x
, x
+ N
), N
);
145 BOOST_TEST_EQ( boost::detail::distance( x
.begin(), x
.end() ), x
.size() );
148 return boost::report_errors();