Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

46 righe
1.0 KiB

  1. #pragma once
  2. #include <cpputils/mp/misc/when.h>
  3. #include <cpputils/mp/misc/tag_of.h>
  4. #include <cpputils/mp/misc/default.h>
  5. namespace utl {
  6. namespace mp {
  7. namespace __impl
  8. {
  9. struct first_t
  10. {
  11. template<typename T>
  12. constexpr auto operator()(T&& t) const;
  13. };
  14. }
  15. constexpr __impl::first_t first { };
  16. namespace __impl
  17. {
  18. template <typename T, typename = void>
  19. struct first_impl
  20. : first_impl<T, when<true>>
  21. { };
  22. template <typename T, bool condition>
  23. struct first_impl<T, when<condition>>
  24. : default_
  25. {
  26. template <typename ...Args>
  27. static constexpr auto apply(Args&& ...) = delete;
  28. };
  29. template<typename T>
  30. constexpr auto first_t::operator()(T&& t) const
  31. {
  32. using tag_type = tag_of<T>;
  33. using first_type = first_impl<tag_type>;
  34. return first_type::apply(std::forward<T>(t));
  35. }
  36. }
  37. }
  38. }