No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

56 líneas
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. #include <cpputils/mp/operations/unpack.fwd.h>
  7. namespace utl {
  8. namespace mp {
  9. namespace __impl
  10. {
  11. struct length_t
  12. {
  13. template<typename Xs>
  14. constexpr auto operator()(const Xs& xs) const;
  15. };
  16. }
  17. constexpr __impl::length_t length { };
  18. namespace __impl
  19. {
  20. struct length_argn
  21. {
  22. template<typename... Xn>
  23. constexpr c_size_t<sizeof...(Xn)> operator()(const Xn& ...) const
  24. { return { }; }
  25. };
  26. template <typename T, typename = void>
  27. struct length_impl
  28. : length_impl<T, when<true>>
  29. { };
  30. template<typename T, bool condition>
  31. struct length_impl<T, when<condition>>
  32. : default_
  33. {
  34. template<typename Xs>
  35. static constexpr auto apply(const Xs& xs)
  36. { return unpack(xs, length_argn { }); }
  37. };
  38. template<typename Xs>
  39. constexpr auto length_t::operator()(const Xs& xs) const
  40. {
  41. using tag_type = tag_of<Xs>;
  42. using length_impl_type = length_impl<tag_type>;
  43. return length_impl_type::apply(xs);
  44. }
  45. }
  46. }
  47. }