comparable.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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::comparable_operators<typename hana::tag_of<X>::type>::value ||
  23. detail::comparable_operators<typename hana::tag_of<Y>::type>::value
  24. >::type>
  25. constexpr auto operator==(X&& x, Y&& y)
  26. { return hana::equal(static_cast<X&&>(x), static_cast<Y&&>(y)); }
  27. template <typename X, typename Y, typename = typename std::enable_if<
  28. detail::comparable_operators<typename hana::tag_of<X>::type>::value ||
  29. detail::comparable_operators<typename hana::tag_of<Y>::type>::value
  30. >::type>
  31. constexpr auto operator!=(X&& x, Y&& y)
  32. { return hana::not_equal(static_cast<X&&>(x), static_cast<Y&&>(y)); }
  33. } // end namespace operators
  34. } BOOST_HANA_NAMESPACE_END
  35. #endif // !BOOST_HANA_DETAIL_OPERATORS_COMPARABLE_HPP