]> git.donarmstrong.com Git - rsem.git/blob - boost/fusion/iterator/equal_to.hpp
a0387417323ac1857d68dc3a04642045746317cb
[rsem.git] / boost / fusion / iterator / equal_to.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_EQUAL_TO_05052005_1208)
8 #define FUSION_EQUAL_TO_05052005_1208
9
10 #include <boost/type_traits/is_same.hpp>
11 #include <boost/fusion/support/tag_of.hpp>
12 #include <boost/type_traits/add_const.hpp>
13 #include <boost/fusion/support/is_iterator.hpp>
14 #include <boost/mpl/and.hpp>
15 #include <boost/utility/enable_if.hpp>
16
17 namespace boost { namespace fusion
18 {
19     // Special tags:
20     struct iterator_facade_tag; // iterator facade tag
21     struct boost_array_iterator_tag; // boost::array iterator tag
22     struct mpl_iterator_tag; // mpl sequence iterator tag
23     struct std_pair_iterator_tag; // std::pair iterator tag
24
25     namespace extension
26     {
27         template <typename Tag>
28         struct equal_to_impl
29         {
30             // default implementation
31             template <typename I1, typename I2>
32             struct apply
33                 : is_same<typename add_const<I1>::type, typename add_const<I2>::type>
34             {};
35         };
36
37         template <>
38         struct equal_to_impl<iterator_facade_tag>
39         {
40             template <typename I1, typename I2>
41             struct apply : I1::template equal_to<I1, I2> {};
42         };
43
44         template <>
45         struct equal_to_impl<boost_array_iterator_tag>;
46
47         template <>
48         struct equal_to_impl<mpl_iterator_tag>;
49
50         template <>
51         struct equal_to_impl<std_pair_iterator_tag>;
52     }
53
54     namespace result_of
55     {
56         template <typename I1, typename I2>
57         struct equal_to
58             : extension::equal_to_impl<typename detail::tag_of<I1>::type>::
59                 template apply<I1, I2>
60         {};
61     }
62
63     namespace iterator_operators
64     {
65         template <typename Iter1, typename Iter2>
66         inline typename 
67         enable_if<
68             mpl::and_<is_fusion_iterator<Iter1>, is_fusion_iterator<Iter2> >
69             , bool
70             >::type
71         operator==(Iter1 const&, Iter2 const&)
72         {
73             return result_of::equal_to<Iter1, Iter2>::value;
74         }
75
76         template <typename Iter1, typename Iter2>
77         inline typename 
78         enable_if<
79             mpl::and_<is_fusion_iterator<Iter1>, is_fusion_iterator<Iter2> >
80             , bool
81             >::type
82         operator!=(Iter1 const&, Iter2 const&)
83         {
84             return !result_of::equal_to<Iter1, Iter2>::value;
85         }
86     }
87
88     using iterator_operators::operator==;
89     using iterator_operators::operator!=;
90 }}
91
92 #endif
93