| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2011 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/fusion/support/config.hpp> |
| 11 | #include <boost/type_traits/is_same.hpp> |
| 12 | #include <boost/fusion/support/tag_of.hpp> |
| 13 | #include <boost/type_traits/add_const.hpp> |
| 14 | #include <boost/fusion/support/is_iterator.hpp> |
| 15 | #include <boost/mpl/and.hpp> |
| 16 | #include <boost/utility/enable_if.hpp> |
| 17 | |
| 18 | namespace boost { namespace fusion |
| 19 | { |
| 20 | // Special tags: |
| 21 | struct iterator_facade_tag; // iterator facade tag |
| 22 | struct boost_array_iterator_tag; // boost::array iterator tag |
| 23 | struct mpl_iterator_tag; // mpl sequence iterator tag |
| 24 | struct std_pair_iterator_tag; // std::pair iterator tag |
| 25 | |
| 26 | namespace extension |
| 27 | { |
| 28 | template <typename Tag> |
| 29 | struct equal_to_impl |
| 30 | { |
| 31 | // default implementation |
| 32 | template <typename I1, typename I2> |
| 33 | struct apply |
| 34 | : is_same<typename add_const<I1>::type, typename add_const<I2>::type> |
| 35 | {}; |
| 36 | }; |
| 37 | |
| 38 | template <> |
| 39 | struct equal_to_impl<iterator_facade_tag> |
| 40 | { |
| 41 | template <typename It1, typename It2, typename Tag1, typename Tag2> |
| 42 | struct dispatch : mpl::false_ {}; |
| 43 | |
| 44 | template <typename It1, typename It2, typename Tag> |
| 45 | struct dispatch<It1, It2, Tag, Tag> // same tag |
| 46 | : It1::template equal_to<It1, It2> |
| 47 | {}; |
| 48 | |
| 49 | template<typename It1, typename It2> |
| 50 | struct apply : dispatch<It1, It2, |
| 51 | typename It1::fusion_tag, typename It2::fusion_tag> |
| 52 | {}; |
| 53 | }; |
| 54 | |
| 55 | template <> |
| 56 | struct equal_to_impl<boost_array_iterator_tag>; |
| 57 | |
| 58 | template <> |
| 59 | struct equal_to_impl<mpl_iterator_tag>; |
| 60 | |
| 61 | template <> |
| 62 | struct equal_to_impl<std_pair_iterator_tag>; |
| 63 | } |
| 64 | |
| 65 | namespace result_of |
| 66 | { |
| 67 | template <typename I1, typename I2> |
| 68 | struct equal_to |
| 69 | : extension::equal_to_impl<typename detail::tag_of<I1>::type>:: |
| 70 | template apply<I1, I2> |
| 71 | {}; |
| 72 | } |
| 73 | |
| 74 | namespace iterator_operators |
| 75 | { |
| 76 | template <typename Iter1, typename Iter2> |
| 77 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
| 78 | inline typename |
| 79 | boost::enable_if< |
| 80 | mpl::and_<is_fusion_iterator<Iter1>, is_fusion_iterator<Iter2> > |
| 81 | , bool |
| 82 | >::type |
| 83 | operator==(Iter1 const&, Iter2 const&) |
| 84 | { |
| 85 | return result_of::equal_to<Iter1, Iter2>::value; |
| 86 | } |
| 87 | |
| 88 | template <typename Iter1, typename Iter2> |
| 89 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
| 90 | inline typename |
| 91 | boost::enable_if< |
| 92 | mpl::and_<is_fusion_iterator<Iter1>, is_fusion_iterator<Iter2> > |
| 93 | , bool |
| 94 | >::type |
| 95 | operator!=(Iter1 const&, Iter2 const&) |
| 96 | { |
| 97 | return !result_of::equal_to<Iter1, Iter2>::value; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | using iterator_operators::operator==; |
| 102 | using iterator_operators::operator!=; |
| 103 | }} |
| 104 | |
| 105 | #endif |
| 106 | |
| 107 | |