comparable.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*!
  2. @file
  3. Defines operators for Comparables.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_DETAIL_OPERATORS_COMPARABLE_HPP
  9. #define BOOST_HANA_DETAIL_OPERATORS_COMPARABLE_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/tag_of.hpp>
  12. #include <boost/hana/fwd/equal.hpp>
  13. #include <boost/hana/fwd/not_equal.hpp>
  14. #include <type_traits>
  15. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  16. template <typename Tag>
  17. struct comparable_operators {
  18. static constexpr bool value = false;
  19. };
  20. namespace operators {
  21. template <typename X, typename Y, typename = typename std::enable_if<
  22. !detail::has_idempotent_tag<X>::value &&
  23. !detail::has_idempotent_tag<Y>::value &&
  24. (detail::comparable_operators<
  25. typename hana::tag_of<X>::type>::value ||
  26. detail::comparable_operators<
  27. typename hana::tag_of<Y>::type>::value)
  28. >::type>
  29. constexpr auto operator==(X&& x, Y&& y)
  30. { return hana::equal(static_cast<X&&>(x), static_cast<Y&&>(y)); }
  31. template <typename X, typename Y, typename = typename std::enable_if<
  32. !detail::has_idempotent_tag<X>::value &&
  33. !detail::has_idempotent_tag<Y>::value &&
  34. (detail::comparable_operators<
  35. typename hana::tag_of<X>::type>::value ||
  36. detail::comparable_operators<
  37. typename hana::tag_of<Y>::type>::value)
  38. >::type>
  39. constexpr auto operator!=(X&& x, Y&& y)
  40. { return hana::not_equal(static_cast<X&&>(x), static_cast<Y&&>(y)); }
  41. } // end namespace operators
  42. } BOOST_HANA_NAMESPACE_END
  43. #endif // !BOOST_HANA_DETAIL_OPERATORS_COMPARABLE_HPP