1
/*=============================================================================
2
Copyright (c) 2001-2006 Joel de Guzman
3
Copyright (c) 2006 Dan Marsden
5
Distributed under the Boost Software License, Version 1.0. (See accompanying
6
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
==============================================================================*/
8
#if !defined(FUSION_DISTANCE_IMPL_20060124_2033)
9
#define FUSION_DISTANCE_IMPL_20060124_2033
11
#include <boost/mpl/eval_if.hpp>
12
#include <boost/mpl/placeholders.hpp>
13
#include <boost/mpl/assert.hpp>
14
#include <boost/fusion/iterator/distance.hpp>
15
#include <boost/fusion/support/category_of.hpp>
16
#include <boost/fusion/algorithm/query/find_if.hpp>
17
#include <boost/fusion/sequence/intrinsic/end.hpp>
18
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
19
#include <boost/type_traits/is_same.hpp>
21
namespace boost { namespace fusion {
23
struct zip_view_iterator_tag;
25
struct random_access_iterator_tag;
29
template<typename FoundIt, typename SearchIt>
32
typedef typename result_of::find_if<
33
typename SearchIt::iterators, is_same<traits::category_of<mpl::_>, random_access_iterator_tag> > finder;
35
BOOST_MPL_ASSERT_NOT((is_same<typename finder::type, result_of::end<typename SearchIt::iterators> >));
37
typedef typename result_of::distance<FoundIt, typename finder::type>::type type;
40
template<typename It1, typename It2>
41
struct default_distance
42
: result_of::distance<
43
typename result_of::value_at_c<typename It1::iterators, 0>::type,
44
typename result_of::value_at_c<typename It2::iterators, 0>::type>
47
template<typename It1, typename It2>
48
struct zip_view_iterator_distance
50
typedef typename result_of::find_if<
51
typename It1::iterators, is_same<traits::category_of<mpl::_>, random_access_iterator_tag> > finder;
53
typedef typename mpl::eval_if<
54
is_same<typename finder::type, typename result_of::end<typename It1::iterators>::type>,
55
detail::default_distance<It1, It2> ,
56
detail::best_distance<typename finder::type, It2> >::type type;
62
template<typename Tag>
66
struct distance_impl<zip_view_iterator_tag>
68
template<typename It1, typename It2>
70
: detail::zip_view_iterator_distance<It1, It2>::type
72
static typename detail::zip_view_iterator_distance<It1, It2>::type
73
call(It1 const& it1, It2 const& it2)
75
return typename detail::zip_view_iterator_distance<It1, It2>::type();