1 /*=============================================================================
2 Copyright (c) 2001-2006 Joel de Guzman
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
10 #include <boost/fusion/iterator/detail/distance.hpp>
11 #include <boost/fusion/support/category_of.hpp>
13 #include <boost/mpl/int.hpp>
14 #include <boost/mpl/assert.hpp>
15 #include <boost/type_traits/is_same.hpp>
17 #include <boost/fusion/support/tag_of.hpp>
19 namespace boost
{ namespace fusion
21 struct random_access_traversal_tag
;
24 struct iterator_facade_tag
; // iterator facade tag
25 struct array_iterator_tag
; // boost::array iterator tag
26 struct mpl_iterator_tag
; // mpl sequence iterator tag
27 struct std_pair_iterator_tag
; // std::pair iterator tag
31 template <typename Tag
>
34 // default implementation
35 template <typename First
, typename Last
>
36 struct apply
: distance_detail::linear_distance
<First
, Last
>
38 BOOST_MPL_ASSERT_NOT((traits::is_random_access
<First
>));
39 BOOST_MPL_ASSERT_NOT((traits::is_random_access
<Last
>));
44 struct distance_impl
<iterator_facade_tag
>
46 template <typename First
, typename Last
>
47 struct apply
: First::template distance
<First
, Last
> {};
51 struct distance_impl
<array_iterator_tag
>;
54 struct distance_impl
<mpl_iterator_tag
>;
57 struct distance_impl
<std_pair_iterator_tag
>;
62 template <typename First
, typename Last
>
64 : extension::distance_impl
<typename
detail::tag_of
<First
>::type
>::
65 template apply
<First
, Last
>
67 typedef typename
extension::distance_impl
<typename
detail::tag_of
<First
>::type
>::
68 template apply
<First
, Last
>::type distance_application
;
69 BOOST_STATIC_CONSTANT(int, value
= distance_application::value
);
73 template <typename First
, typename Last
>
74 inline typename
result_of::distance
<First
, Last
>::type
75 distance(First
const& a
, Last
const& b
)
77 return result_of::distance
<First
, Last
>::call(a
,b
);