equal_to.hpp 3.1 KB

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