您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

63 行
1.6 KiB

  1. #pragma once
  2. #include <cpputils/mp/core/const.h>
  3. #include <cpputils/mp/util/when.h>
  4. #include <cpputils/mp/util/tag_of.h>
  5. #include <cpputils/mp/util/default.h>
  6. #include <cpputils/mp/operations/if.h>
  7. namespace utl {
  8. namespace mp {
  9. namespace __impl
  10. {
  11. struct and_t
  12. {
  13. template<typename X, typename Y>
  14. constexpr auto operator()(X&& x, Y&& y) const;
  15. template<typename X, typename... Y>
  16. constexpr auto operator()(X&& x, Y&&... y) const;
  17. };
  18. }
  19. constexpr __impl::and_t and_ { };
  20. namespace __impl
  21. {
  22. template <typename T, typename = void>
  23. struct and_impl
  24. : and_impl<T, when<true>>
  25. { };
  26. template <typename T, bool condition>
  27. struct and_impl<T, when<condition>>
  28. : default_
  29. {
  30. template <typename X, typename Y>
  31. static constexpr auto apply(X&& x, Y&& y)
  32. { return if_(x, static_cast<Y&&>(y), x); }
  33. };
  34. template <typename X, typename Y>
  35. constexpr auto and_t::operator()(X&& x, Y&& y) const
  36. {
  37. using tag_type = tag_of<X>;
  38. using and_impl_type = and_impl<tag_type>;
  39. return and_impl_type::apply(std::forward<X>(x), std::forward<Y>(y));
  40. };
  41. /* TODO
  42. template <typename X, typename ...Y>
  43. constexpr auto and_t::operator()(X&& x, Y&& ...y) const
  44. {
  45. return detail::variadic::foldl1(
  46. *this,
  47. static_cast<X&&>(x),
  48. static_cast<Y&&>(y)...
  49. );
  50. }
  51. */
  52. }
  53. }
  54. }