greater_equal.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*!
  2. @file
  3. Defines `boost::hana::greater_equal`.
  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_GREATER_EQUAL_HPP
  9. #define BOOST_HANA_GREATER_EQUAL_HPP
  10. #include <boost/hana/fwd/greater_equal.hpp>
  11. #include <boost/hana/concept/orderable.hpp>
  12. #include <boost/hana/config.hpp>
  13. #include <boost/hana/core/common.hpp>
  14. #include <boost/hana/core/to.hpp>
  15. #include <boost/hana/core/dispatch.hpp>
  16. #include <boost/hana/detail/concepts.hpp>
  17. #include <boost/hana/detail/has_common_embedding.hpp>
  18. #include <boost/hana/detail/nested_than.hpp> // required by fwd decl
  19. #include <boost/hana/if.hpp>
  20. #include <boost/hana/not.hpp>
  21. BOOST_HANA_NAMESPACE_BEGIN
  22. //! @cond
  23. template <typename X, typename Y>
  24. constexpr decltype(auto) greater_equal_t::operator()(X&& x, Y&& y) const {
  25. using T = typename hana::tag_of<X>::type;
  26. using U = typename hana::tag_of<Y>::type;
  27. using GreaterEqual = BOOST_HANA_DISPATCH_IF(
  28. decltype(greater_equal_impl<T, U>{}),
  29. hana::Orderable<T>::value &&
  30. hana::Orderable<U>::value
  31. );
  32. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  33. static_assert(hana::Orderable<T>::value,
  34. "hana::greater_equal(x, y) requires 'x' to be Orderable");
  35. static_assert(hana::Orderable<U>::value,
  36. "hana::greater_equal(x, y) requires 'y' to be Orderable");
  37. #endif
  38. return GreaterEqual::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
  39. }
  40. //! @endcond
  41. template <typename T, typename U, bool condition>
  42. struct greater_equal_impl<T, U, when<condition>> : default_ {
  43. template <typename X, typename Y>
  44. static constexpr decltype(auto) apply(X x, Y y) {
  45. return hana::not_(hana::less(static_cast<X&&>(x),
  46. static_cast<Y&&>(y)));
  47. }
  48. };
  49. // Cross-type overload
  50. template <typename T, typename U>
  51. struct greater_equal_impl<T, U, when<
  52. detail::has_nontrivial_common_embedding<Orderable, T, U>::value
  53. >> {
  54. using C = typename hana::common<T, U>::type;
  55. template <typename X, typename Y>
  56. static constexpr decltype(auto) apply(X&& x, Y&& y) {
  57. return hana::greater_equal(hana::to<C>(static_cast<X&&>(x)),
  58. hana::to<C>(static_cast<Y&&>(y)));
  59. }
  60. };
  61. BOOST_HANA_NAMESPACE_END
  62. #endif // !BOOST_HANA_GREATER_EQUAL_HPP