orderable.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*!
  2. @file
  3. Defines operators for Orderables.
  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_ORDERABLE_HPP
  9. #define BOOST_HANA_DETAIL_OPERATORS_ORDERABLE_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/tag_of.hpp>
  12. #include <boost/hana/fwd/greater.hpp>
  13. #include <boost/hana/fwd/greater_equal.hpp>
  14. #include <boost/hana/fwd/less.hpp>
  15. #include <boost/hana/fwd/less_equal.hpp>
  16. #include <type_traits>
  17. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  18. template <typename Tag>
  19. struct orderable_operators {
  20. static constexpr bool value = false;
  21. };
  22. namespace operators {
  23. template <typename X, typename Y, typename = typename std::enable_if<
  24. detail::orderable_operators<typename hana::tag_of<X>::type>::value ||
  25. detail::orderable_operators<typename hana::tag_of<Y>::type>::value
  26. >::type>
  27. constexpr auto operator<(X&& x, Y&& y)
  28. { return hana::less(static_cast<X&&>(x), static_cast<Y&&>(y)); }
  29. template <typename X, typename Y, typename = typename std::enable_if<
  30. detail::orderable_operators<typename hana::tag_of<X>::type>::value ||
  31. detail::orderable_operators<typename hana::tag_of<Y>::type>::value
  32. >::type>
  33. constexpr auto operator>(X&& x, Y&& y)
  34. { return hana::greater(static_cast<X&&>(x), static_cast<Y&&>(y)); }
  35. template <typename X, typename Y, typename = typename std::enable_if<
  36. detail::orderable_operators<typename hana::tag_of<X>::type>::value ||
  37. detail::orderable_operators<typename hana::tag_of<Y>::type>::value
  38. >::type>
  39. constexpr auto operator<=(X&& x, Y&& y)
  40. { return hana::less_equal(static_cast<X&&>(x), static_cast<Y&&>(y)); }
  41. template <typename X, typename Y, typename = typename std::enable_if<
  42. detail::orderable_operators<typename hana::tag_of<X>::type>::value ||
  43. detail::orderable_operators<typename hana::tag_of<Y>::type>::value
  44. >::type>
  45. constexpr auto operator>=(X&& x, Y&& y)
  46. { return hana::greater_equal(static_cast<X&&>(x), static_cast<Y&&>(y)); }
  47. } // end namespace operators
  48. } BOOST_HANA_NAMESPACE_END
  49. #endif // !BOOST_HANA_DETAIL_OPERATORS_ORDERABLE_HPP