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.

54 line
1.2 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. template<typename T, typename = void>
  10. struct value_impl;
  11. }
  12. template <typename T>
  13. constexpr auto value()
  14. {
  15. using t_clean_type = clean_type<T>;
  16. using tag_type = tag_of<T>;
  17. using value_impl_type = __impl::value_impl<tag_type>;
  18. return value_impl_type::template apply<t_clean_type>();
  19. }
  20. template <typename T>
  21. constexpr decltype(auto) value(T const&)
  22. { return value<T>(); }
  23. namespace __impl
  24. {
  25. template <typename T, typename>
  26. struct value_impl
  27. : value_impl<T, when<true>>
  28. { };
  29. template <typename T, bool condition>
  30. struct value_impl<T, when<condition>>
  31. : default_
  32. {
  33. template <typename ...Args>
  34. static constexpr auto apply(Args&& ...args) = delete;
  35. };
  36. template <typename T>
  37. struct value_impl<tag_integral_constant<T>>
  38. {
  39. template <typename C>
  40. static constexpr auto apply()
  41. { return C::value; }
  42. };
  43. }
  44. }
  45. }