count.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_COUNT_09162005_0158)
  7. #define FUSION_COUNT_09162005_0158
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/config.hpp>
  10. #include <boost/mpl/or.hpp>
  11. #include <boost/type_traits/is_convertible.hpp>
  12. #include <boost/fusion/support/detail/access.hpp>
  13. #if defined (BOOST_MSVC)
  14. # pragma warning(push)
  15. # pragma warning (disable: 4512) // assignment operator could not be generated.
  16. #endif
  17. namespace boost { namespace fusion { namespace detail
  18. {
  19. template <bool is_convertible>
  20. struct compare_convertible;
  21. // T1 is convertible to T2 or vice versa
  22. template <>
  23. struct compare_convertible<true>
  24. {
  25. template <typename T1, typename T2>
  26. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  27. static bool
  28. call(T1 const& x, T2 const& y)
  29. {
  30. return x == y;
  31. }
  32. };
  33. // T1 is NOT convertible to T2 NOR vice versa
  34. template <>
  35. struct compare_convertible<false>
  36. {
  37. template <typename T1, typename T2>
  38. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  39. static bool
  40. call(T1 const&, T2 const&)
  41. {
  42. return false;
  43. }
  44. };
  45. template <typename T1>
  46. struct count_compare
  47. {
  48. typedef typename detail::call_param<T1>::type param;
  49. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  50. count_compare(param in_x)
  51. : x(in_x) {}
  52. template <typename T2>
  53. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  54. bool
  55. operator()(T2 const& y) const
  56. {
  57. return
  58. compare_convertible<
  59. mpl::or_<
  60. is_convertible<T1, T2>
  61. , is_convertible<T2, T1>
  62. >::value
  63. >::call(x, y);
  64. }
  65. param x;
  66. };
  67. }}}
  68. #if defined (BOOST_MSVC)
  69. # pragma warning(pop)
  70. #endif
  71. #endif