]> git.donarmstrong.com Git - rsem.git/blob - boost/fusion/iterator/detail/distance.hpp
e4c0a5e7cc47525b303aa655967e1fb8c165a1de
[rsem.git] / boost / fusion / iterator / detail / distance.hpp
1 /*=============================================================================
2     Copyright (c) 2001-2006 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_0730)
8 #define FUSION_DISTANCE_09172005_0730
9
10 #include <boost/mpl/int.hpp>
11 #include <boost/mpl/if.hpp>
12 #include <boost/mpl/eval_if.hpp>
13 #include <boost/mpl/next.hpp>
14 #include <boost/mpl/identity.hpp>
15 #include <boost/fusion/iterator/next.hpp>
16 #include <boost/fusion/iterator/equal_to.hpp>
17
18 namespace boost { namespace fusion { namespace distance_detail
19 {
20     // Default distance implementation, linear
21     // search for the Last iterator.
22
23     template <typename First, typename Last>
24     struct linear_distance;
25
26     template <typename First, typename Last>
27     struct next_distance
28     {
29         typedef typename 
30             mpl::next<
31                 typename linear_distance<
32                     typename result_of::next<First>::type
33                   , Last
34                 >::type
35             >::type 
36         type;
37     };
38
39     template <typename First, typename Last>
40     struct linear_distance
41         : mpl::eval_if<
42             result_of::equal_to<First, Last>
43           , mpl::identity<mpl::int_<0> >
44           , next_distance<First, Last>
45         >::type
46     {
47         typedef typename
48             mpl::eval_if<
49                 result_of::equal_to<First, Last>
50               , mpl::identity<mpl::int_<0> >
51               , next_distance<First, Last>
52             >::type
53         type;
54
55         static type
56         call(First const&, Last const&)
57         {
58             return type();
59         }
60     };
61
62 }}}
63
64 #endif