///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2014-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/intrusive for documentation. // ///////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP #define BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP #ifndef BOOST_CONFIG_HPP # include #endif #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include #include #include #include #include namespace boost{ namespace iterators{ struct incrementable_traversal_tag; struct single_pass_traversal_tag; struct forward_traversal_tag; struct bidirectional_traversal_tag; struct random_access_traversal_tag; namespace detail{ template struct iterator_category_with_traversal; } //namespace boost{ } //namespace iterators{ } //namespace detail{ namespace boost { namespace intrusive { using boost::movelib::iterator_traits; using boost::movelib::iter_difference; using boost::movelib::iter_value; using boost::movelib::iter_category; using boost::movelib::iter_size; //////////////////// // iterator //////////////////// template struct iterator { typedef Category iterator_category; typedef T value_type; typedef Difference difference_type; typedef Pointer pointer; typedef Reference reference; }; //////////////////////////////////////////////////////////////////////////////// // Conversion from boost::iterator traversals to std tags //////////////////////////////////////////////////////////////////////////////// template struct get_std_category_from_tag { typedef Tag type; }; template struct get_std_category_from_tag > { typedef std::input_iterator_tag type; }; template struct get_std_category_from_tag > { typedef std::input_iterator_tag type; }; template struct get_std_category_from_tag > { typedef std::input_iterator_tag type; }; template struct get_std_category_from_tag > { typedef std::bidirectional_iterator_tag type; }; template struct get_std_category_from_tag > { typedef std::random_access_iterator_tag type; }; template struct get_std_category_from_it : get_std_category_from_tag< typename boost::intrusive::iter_category::type > {}; //////////////////////////////////////// // iterator_[dis|en]able_if_tag //////////////////////////////////////// template struct iterator_enable_if_tag : ::boost::move_detail::enable_if_c < ::boost::move_detail::is_same < typename get_std_category_from_it::type , Tag >::value , R> {}; template struct iterator_disable_if_tag : ::boost::move_detail::enable_if_c < !::boost::move_detail::is_same < typename get_std_category_from_it::type , Tag >::value , R> {}; //////////////////////////////////////// // iterator_[dis|en]able_if_tag //////////////////////////////////////// template struct iterator_enable_if_convertible_tag : ::boost::move_detail::enable_if_c < ::boost::move_detail::is_same_or_convertible < typename get_std_category_from_it::type , Tag >::value && !::boost::move_detail::is_same_or_convertible < typename get_std_category_from_it::type , Tag2 >::value , R> {}; //////////////////////////////////////// // iterator_[dis|en]able_if_tag_difference_type //////////////////////////////////////// template struct iterator_enable_if_tag_difference_type : iterator_enable_if_tag::type> {}; template struct iterator_disable_if_tag_difference_type : iterator_disable_if_tag::type> {}; //////////////////// // advance //////////////////// template inline typename iterator_enable_if_tag::type iterator_advance(InputIt& it, typename iter_difference::type n) { while(n--) ++it; } template typename iterator_enable_if_tag::type iterator_advance(InputIt& it, typename iter_difference::type n) { while(n--) ++it; } template inline typename iterator_enable_if_tag::type iterator_advance(InputIt& it, typename iter_difference::type n) { for (; 0 < n; --n) ++it; for (; n < 0; ++n) --it; } template inline typename iterator_enable_if_tag::type iterator_advance(InputIt& it, Distance n) { it += n; } template inline typename iterator_enable_if_tag::type make_iterator_advance(InputIt it, Distance n) { (iterator_advance)(it, n); return it; } template inline void iterator_uadvance(It& it, typename iter_size::type n) { (iterator_advance)(it, (typename iterator_traits::difference_type)n); } template inline It make_iterator_uadvance(It it, typename iter_size::type n) { (iterator_uadvance)(it, n); return it; } //////////////////////////////////////// // iterator_distance //////////////////////////////////////// template inline typename iterator_disable_if_tag_difference_type ::type iterator_distance(InputIt first, InputIt last) { typename iter_difference::type off = 0; while(first != last){ ++off; ++first; } return off; } template inline typename iterator_enable_if_tag_difference_type ::type iterator_distance(InputIt first, InputIt last) { typename iter_difference::type off = last - first; return off; } //////////////////////////////////////// // iterator_udistance //////////////////////////////////////// template inline typename iter_size::type iterator_udistance(It first, It last) { return (typename iter_size::type)(iterator_distance)(first, last); } //////////////////////////////////////// // iterator_next //////////////////////////////////////// template inline InputIt iterator_next(InputIt it, typename iter_difference::type n) { (iterator_advance)(it, n); return it; } template inline InputIt iterator_unext(InputIt it, typename iterator_traits::size_type n) { (iterator_uadvance)(it, n); return it; } //////////////////////////////////////// // iterator_arrow_result //////////////////////////////////////// template inline typename iterator_traits::pointer iterator_arrow_result(const I &i) { return i.operator->(); } template inline T * iterator_arrow_result(T *p) { return p; } } //namespace intrusive } //namespace boost #endif //BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP