1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2014-2014
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/intrusive for documentation.
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP
14 #define BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP
16 #ifndef BOOST_CONFIG_HPP
17 # include <boost/config.hpp>
20 #if defined(BOOST_HAS_PRAGMA_ONCE)
25 #include <boost/intrusive/detail/std_fwd.hpp>
26 #include <boost/intrusive/detail/workaround.hpp>
27 #include <boost/move/detail/iterator_traits.hpp>
28 #include <boost/move/detail/meta_utils_core.hpp>
33 struct incrementable_traversal_tag;
34 struct single_pass_traversal_tag;
35 struct forward_traversal_tag;
36 struct bidirectional_traversal_tag;
37 struct random_access_traversal_tag;
41 template <class Category, class Traversal>
42 struct iterator_category_with_traversal;
45 } //namespace iterators{
51 using boost::movelib::iterator_traits;
56 template<class Category, class T, class Difference, class Pointer, class Reference>
59 typedef Category iterator_category;
61 typedef Difference difference_type;
62 typedef Pointer pointer;
63 typedef Reference reference;
66 ////////////////////////////////////////
67 // iterator_[dis|en]able_if_boost_iterator
68 ////////////////////////////////////////
70 struct is_boost_iterator
72 static const bool value = false;
75 template<class Category, class Traversal>
76 struct is_boost_iterator< boost::iterators::detail::iterator_category_with_traversal<Category, Traversal> >
78 static const bool value = true;
81 template<class I, class R = void>
82 struct iterator_enable_if_boost_iterator
83 : ::boost::move_detail::enable_if_c
84 < is_boost_iterator<typename boost::intrusive::iterator_traits<I>::iterator_category >::value
88 ////////////////////////////////////////
89 // iterator_[dis|en]able_if_tag
90 ////////////////////////////////////////
91 template<class I, class Tag, class R = void>
92 struct iterator_enable_if_tag
93 : ::boost::move_detail::enable_if_c
94 < ::boost::move_detail::is_same
95 < typename boost::intrusive::iterator_traits<I>::iterator_category
101 template<class I, class Tag, class R = void>
102 struct iterator_disable_if_tag
103 : ::boost::move_detail::enable_if_c
104 < !::boost::move_detail::is_same
105 < typename boost::intrusive::iterator_traits<I>::iterator_category
111 ////////////////////////////////////////
112 // iterator_[dis|en]able_if_tag
113 ////////////////////////////////////////
114 template<class I, class Tag, class Tag2, class R = void>
115 struct iterator_enable_if_convertible_tag
116 : ::boost::move_detail::enable_if_c
117 < ::boost::move_detail::is_same_or_convertible
118 < typename boost::intrusive::iterator_traits<I>::iterator_category
121 !::boost::move_detail::is_same_or_convertible
122 < typename boost::intrusive::iterator_traits<I>::iterator_category
128 ////////////////////////////////////////
129 // iterator_[dis|en]able_if_tag_difference_type
130 ////////////////////////////////////////
131 template<class I, class Tag>
132 struct iterator_enable_if_tag_difference_type
133 : iterator_enable_if_tag<I, Tag, typename boost::intrusive::iterator_traits<I>::difference_type>
136 template<class I, class Tag>
137 struct iterator_disable_if_tag_difference_type
138 : iterator_disable_if_tag<I, Tag, typename boost::intrusive::iterator_traits<I>::difference_type>
145 template<class InputIt, class Distance>
146 BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_tag<InputIt, std::input_iterator_tag>::type
147 iterator_advance(InputIt& it, Distance n)
153 template<class InputIt, class Distance>
154 typename iterator_enable_if_tag<InputIt, std::forward_iterator_tag>::type
155 iterator_advance(InputIt& it, Distance n)
161 template<class InputIt, class Distance>
162 BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_tag<InputIt, std::bidirectional_iterator_tag>::type
163 iterator_advance(InputIt& it, Distance n)
171 template<class InputIt, class Distance>
172 BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_tag<InputIt, std::random_access_iterator_tag>::type
173 iterator_advance(InputIt& it, Distance n)
178 template<class InputIt, class Distance>
179 BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_convertible_tag
180 <InputIt, const boost::iterators::incrementable_traversal_tag&, const boost::iterators::single_pass_traversal_tag&>::type
181 iterator_advance(InputIt& it, Distance n)
187 template<class InputIt, class Distance>
188 BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_convertible_tag
189 <InputIt, const boost::iterators::single_pass_traversal_tag &, const boost::iterators::forward_traversal_tag&>::type
190 iterator_advance(InputIt& it, Distance n)
196 template<class InputIt, class Distance>
197 BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_convertible_tag
198 <InputIt, const boost::iterators::forward_traversal_tag&, const boost::iterators::bidirectional_traversal_tag&>::type
199 iterator_advance(InputIt& it, Distance n)
205 template<class InputIt, class Distance>
206 BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_convertible_tag
207 <InputIt, const boost::iterators::bidirectional_traversal_tag&, const boost::iterators::random_access_traversal_tag&>::type
208 iterator_advance(InputIt& it, Distance n)
218 template<class InputIt, class Distance>
219 BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_convertible_tag
220 <InputIt, const boost::iterators::random_access_traversal_tag&, const fake&>::type
221 iterator_advance(InputIt& it, Distance n)
229 template<class InputIt> inline
230 typename iterator_disable_if_tag_difference_type
231 <InputIt, std::random_access_iterator_tag>::type
232 iterator_distance(InputIt first, InputIt last)
234 typename iterator_traits<InputIt>::difference_type off = 0;
235 while(first != last){
242 template<class InputIt>
243 BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_tag_difference_type
244 <InputIt, std::random_access_iterator_tag>::type
245 iterator_distance(InputIt first, InputIt last)
247 typename iterator_traits<InputIt>::difference_type off = last - first;
252 BOOST_INTRUSIVE_FORCEINLINE typename iterator_traits<I>::pointer iterator_arrow_result(const I &i)
253 { return i.operator->(); }
256 BOOST_INTRUSIVE_FORCEINLINE T * iterator_arrow_result(T *p)
259 } //namespace intrusive
262 #endif //BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP