You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 rivejä
1.4 KiB

  1. #pragma once
  2. #include <cpputils/mp/core/const.h>
  3. #include <cpputils/mp/misc/when.h>
  4. #include <cpputils/mp/misc/tag_of.h>
  5. #include <cpputils/mp/misc/default.h>
  6. #include <cpputils/mp/operations/logical/not.h>
  7. #include <cpputils/mp/operations/compare/less.h>
  8. namespace utl {
  9. namespace mp {
  10. namespace __impl
  11. {
  12. struct less_equal_t
  13. {
  14. template<typename L, typename R>
  15. constexpr auto operator()(const L& l, const R& r) const;
  16. };
  17. }
  18. constexpr __impl::less_equal_t less_equal { };
  19. namespace __impl
  20. {
  21. template <typename L, typename R, typename = void>
  22. struct less_equal_impl
  23. : less_equal_impl<L, R, when<true>>
  24. { };
  25. template <typename T, typename U, bool condition>
  26. struct less_equal_impl<T, U, when<condition>>
  27. : default_
  28. {
  29. template <typename X, typename Y>
  30. static constexpr auto apply(X&& x, Y&& y)
  31. { return not_(less(static_cast<Y&&>(y), static_cast<X&&>(x))); }
  32. };
  33. template<typename L, typename R>
  34. constexpr auto less_equal_t::operator()(const L& l, const R& r) const
  35. {
  36. using l_tag_type = tag_of<L>;
  37. using r_tag_type = tag_of<R>;
  38. using less_equal_impl_type = less_equal_impl<l_tag_type, r_tag_type>;
  39. return less_equal_impl_type::apply(l, r);
  40. }
  41. }
  42. }
  43. }