| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2011 Joel de Guzman |
| 3 | |
| 4 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | ==============================================================================*/ |
| 7 | #if !defined(FUSION_FUSION_ITERATOR_10012005_1551) |
| 8 | #define FUSION_FUSION_ITERATOR_10012005_1551 |
| 9 | |
| 10 | #include <boost/fusion/support/config.hpp> |
| 11 | #include <boost/fusion/iterator/value_of.hpp> |
| 12 | #include <boost/fusion/iterator/next.hpp> |
| 13 | #include <boost/fusion/iterator/prior.hpp> |
| 14 | #include <boost/fusion/iterator/advance.hpp> |
| 15 | #include <boost/fusion/iterator/distance.hpp> |
| 16 | #include <boost/fusion/support/category_of.hpp> |
| 17 | #include <boost/mpl/next_prior.hpp> |
| 18 | #include <boost/mpl/advance_fwd.hpp> |
| 19 | #include <boost/mpl/distance_fwd.hpp> |
| 20 | #include <boost/mpl/iterator_tags.hpp> |
| 21 | #include <boost/mpl/eval_if.hpp> |
| 22 | #include <boost/type_traits/is_base_of.hpp> |
| 23 | |
| 24 | namespace boost { namespace fusion { namespace detail |
| 25 | { |
| 26 | |
| 27 | template<class Category> |
| 28 | struct to_mpl_category { |
| 29 | typedef typename mpl::eval_if< |
| 30 | is_base_of<random_access_traversal_tag, Category>, |
| 31 | mpl::random_access_iterator_tag, |
| 32 | mpl::eval_if< |
| 33 | is_base_of<bidirectional_traversal_tag, Category>, |
| 34 | mpl::bidirectional_iterator_tag, |
| 35 | mpl::forward_iterator_tag |
| 36 | > |
| 37 | >::type type; |
| 38 | }; |
| 39 | |
| 40 | }}} |
| 41 | |
| 42 | namespace boost { namespace mpl |
| 43 | { |
| 44 | template <typename Iterator> |
| 45 | struct fusion_iterator |
| 46 | { |
| 47 | typedef typename fusion::result_of::value_of<Iterator>::type type; |
| 48 | typedef typename fusion::traits::category_of<Iterator>::type fusion_category; |
| 49 | typedef typename fusion::detail::to_mpl_category<fusion_category>::type category; |
| 50 | typedef Iterator iterator; |
| 51 | }; |
| 52 | |
| 53 | template <typename Iterator> |
| 54 | struct next<fusion_iterator<Iterator> > |
| 55 | { |
| 56 | typedef fusion_iterator<typename fusion::result_of::next<Iterator>::type> type; |
| 57 | }; |
| 58 | |
| 59 | template <typename Iterator> |
| 60 | struct prior<fusion_iterator<Iterator> > |
| 61 | { |
| 62 | typedef fusion_iterator<typename fusion::result_of::prior<Iterator>::type> type; |
| 63 | }; |
| 64 | |
| 65 | template <typename Iterator, typename N> |
| 66 | struct advance<fusion_iterator<Iterator>, N> |
| 67 | { |
| 68 | typedef fusion_iterator<typename fusion::result_of::advance<Iterator, N>::type> type; |
| 69 | }; |
| 70 | |
| 71 | template <typename First, typename Last> |
| 72 | struct distance<fusion_iterator<First>, fusion_iterator<Last> > |
| 73 | : fusion::result_of::distance<First, Last> |
| 74 | {}; |
| 75 | |
| 76 | }} |
| 77 | |
| 78 | #endif |
| 79 | |
| 80 | |
| 81 | |