equal_to.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(FUSION_EQUAL_TO_05052005_1208)
  7. #define FUSION_EQUAL_TO_05052005_1208
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/type_traits/is_same.hpp>
  10. #include <boost/fusion/support/tag_of.hpp>
  11. #include <boost/type_traits/add_const.hpp>
  12. #include <boost/fusion/support/is_iterator.hpp>
  13. #include <boost/mpl/and.hpp>
  14. #include <boost/utility/enable_if.hpp>
  15. namespace boost { namespace fusion
  16. {
  17. // Special tags:
  18. struct iterator_facade_tag; // iterator facade tag
  19. struct boost_array_iterator_tag; // boost::array iterator tag
  20. struct mpl_iterator_tag; // mpl sequence iterator tag
  21. struct std_pair_iterator_tag; // std::pair iterator tag
  22. namespace extension
  23. {
  24. template <typename Tag>
  25. struct equal_to_impl
  26. {
  27. // default implementation
  28. template <typename I1, typename I2>
  29. struct apply
  30. : is_same<typename add_const<I1>::type, typename add_const<I2>::type>
  31. {};
  32. };
  33. template <>
  34. struct equal_to_impl<iterator_facade_tag>
  35. {
  36. template <typename It1, typename It2, typename Tag1, typename Tag2>
  37. struct dispatch : mpl::false_ {};
  38. template <typename It1, typename It2, typename Tag>
  39. struct dispatch<It1, It2, Tag, Tag> // same tag
  40. : It1::template equal_to<It1, It2>
  41. {};
  42. template<typename It1, typename It2>
  43. struct apply : dispatch<It1, It2,
  44. typename It1::fusion_tag, typename It2::fusion_tag>
  45. {};
  46. };
  47. template <>
  48. struct equal_to_impl<boost_array_iterator_tag>;
  49. template <>
  50. struct equal_to_impl<mpl_iterator_tag>;
  51. template <>
  52. struct equal_to_impl<std_pair_iterator_tag>;
  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. namespace iterator_operators
  63. {
  64. template <typename Iter1, typename Iter2>
  65. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  66. inline typename
  67. boost::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. template <typename Iter1, typename Iter2>
  76. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  77. inline typename
  78. boost::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. using iterator_operators::operator==;
  88. using iterator_operators::operator!=;
  89. }}
  90. #endif