Imported Upstream version 1.49.0
[platform/upstream/boost.git] / boost / fusion / view / zip_view / detail / next_impl.hpp
1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3     Copyright (c) 2006 Dan Marsden
4
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_NEXT_IMPL_20060124_2006)
9 #define FUSION_NEXT_IMPL_20060124_2006
10
11 #include <boost/fusion/view/zip_view/zip_view_iterator_fwd.hpp>
12 #include <boost/fusion/iterator/next.hpp>
13 #include <boost/fusion/algorithm/transformation/transform.hpp>
14 #include <boost/fusion/support/unused.hpp>
15 #include <boost/mpl/eval_if.hpp>
16 #include <boost/mpl/identity.hpp>
17 #include <boost/type_traits/is_same.hpp>
18 #include <boost/type_traits/remove_reference.hpp>
19 #include <boost/type_traits/remove_const.hpp>
20
21 namespace boost { namespace fusion {
22
23     struct zip_view_iterator_tag;
24     
25     namespace detail
26     {
27         struct poly_next
28         {
29             template<typename Sig>
30             struct result;
31
32             template<typename It>
33             struct result<poly_next(It)>
34             {
35                 typedef typename remove_const<
36                     typename remove_reference<It>::type>::type it;
37
38                 typedef typename mpl::eval_if<is_same<it, unused_type>,
39                     mpl::identity<unused_type>,
40                     result_of::next<it> >::type type;
41             };
42
43             template<typename It>
44             typename result<poly_next(It)>::type
45             operator()(const It& it) const
46             {
47                 return fusion::next(it);
48             }
49
50             unused_type operator()(unused_type const&) const
51             {
52                 return unused_type();
53             }
54         };
55     }
56
57     namespace extension
58     {
59         template<typename Tag>
60         struct next_impl;
61
62         template<>
63         struct next_impl<zip_view_iterator_tag>
64         {
65             template<typename Iterator>
66             struct apply
67             {
68                 typedef fusion::zip_view_iterator<
69                     typename result_of::transform<typename Iterator::iterators, detail::poly_next>::type,
70                     typename Iterator::category> type;
71
72                 static type
73                 call(Iterator const& it)
74                 {
75                     return type(
76                         fusion::transform(it.iterators_, detail::poly_next()));
77                 }
78             };
79         };
80     }
81 }}
82
83 #endif