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_DISTANCE_09172005_0721)
8#define FUSION_DISTANCE_09172005_0721
9
10#include <boost/fusion/support/config.hpp>
11#include <boost/fusion/iterator/detail/distance.hpp>
12#include <boost/fusion/support/category_of.hpp>
13
14#include <boost/mpl/int.hpp>
15#include <boost/mpl/assert.hpp>
16#include <boost/type_traits/is_same.hpp>
17
18#include <boost/fusion/support/tag_of.hpp>
19
20namespace boost { namespace fusion
21{
22 struct random_access_traversal_tag;
23
24 // Special tags:
25 struct iterator_facade_tag; // iterator facade tag
26 struct boost_array_iterator_tag; // boost::array iterator tag
27 struct mpl_iterator_tag; // mpl sequence iterator tag
28 struct std_pair_iterator_tag; // std::pair iterator tag
29
30 namespace extension
31 {
32 template <typename Tag>
33 struct distance_impl
34 {
35 // default implementation
36 template <typename First, typename Last>
37 struct apply : distance_detail::linear_distance<First, Last>
38 {};
39 };
40
41 template <>
42 struct distance_impl<iterator_facade_tag>
43 {
44 template <typename First, typename Last>
45 struct apply : First::template distance<First, Last> {};
46 };
47
48 template <>
49 struct distance_impl<boost_array_iterator_tag>;
50
51 template <>
52 struct distance_impl<mpl_iterator_tag>;
53
54 template <>
55 struct distance_impl<std_pair_iterator_tag>;
56 }
57
58 namespace result_of
59 {
60 template <typename First, typename Last>
61 struct distance
62 : extension::distance_impl<typename detail::tag_of<First>::type>::
63 template apply<First, Last>
64 {
65 typedef typename extension::distance_impl<typename detail::tag_of<First>::type>::
66 template apply<First, Last>::type distance_application;
67 BOOST_STATIC_CONSTANT(int, value = distance_application::value);
68 };
69 }
70
71 template <typename First, typename Last>
72 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
73 inline typename result_of::distance<First, Last>::type
74 distance(First const& a, Last const& b)
75 {
76 return result_of::distance<First, Last>::call(a,b);
77 }
78}}
79
80#endif
81

source code of include/boost/fusion/iterator/distance.hpp