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.

55 line
1.3 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. namespace utl {
  7. namespace mp {
  8. namespace __impl
  9. {
  10. struct not_t
  11. {
  12. template<typename X>
  13. constexpr auto operator()(X&& x) const;
  14. };
  15. }
  16. constexpr __impl::not_t not_ { };
  17. namespace __impl
  18. {
  19. template <typename T, typename = void>
  20. struct not_impl
  21. : not_impl<T, when<true>>
  22. { };
  23. template <typename T, bool condition>
  24. struct not_impl<T, when<condition>>
  25. : default_
  26. {
  27. template <typename ...Args>
  28. static constexpr auto apply(Args&& ...) = delete;
  29. };
  30. template <typename T>
  31. struct not_impl<T, when<is_arithmetic<T>::value>>
  32. {
  33. template <typename X>
  34. static constexpr auto apply(const X& x)
  35. { return x ? false : true; }
  36. };
  37. template <typename X>
  38. constexpr auto not_t::operator()(X&& x) const
  39. {
  40. using tag_type = tag_of<X>;
  41. using not_impl_type = not_impl<tag_type>;
  42. return not_impl_type::apply(std::forward<X>(x));
  43. };
  44. }
  45. }
  46. }