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.

52 lines
1.2 KiB

  1. #pragma once
  2. #include <utility>
  3. #include <cpputils/mp/core/const.h>
  4. #include <cpputils/mp/misc/when.h>
  5. #include <cpputils/mp/misc/tag_of.h>
  6. #include <cpputils/mp/misc/default.h>
  7. namespace utl {
  8. namespace mp {
  9. namespace __impl
  10. {
  11. struct at_t
  12. {
  13. template<typename Xs, typename N>
  14. constexpr auto operator()(Xs&& xs, const N& n) const;
  15. };
  16. }
  17. constexpr __impl::at_t at { };
  18. template<size_t N, typename Xs>
  19. constexpr auto at_c(Xs&& xs)
  20. { return at(std::forward<Xs>(xs), c_size_t<N> { }); }
  21. namespace __impl
  22. {
  23. template <typename T, typename = void>
  24. struct at_impl
  25. : at_impl<T, when<true>>
  26. { };
  27. template <typename T, bool condition>
  28. struct at_impl<T, when<condition>>
  29. : default_
  30. {
  31. template <typename ...Args>
  32. static constexpr auto apply(Args&& ...) = delete;
  33. };
  34. template<typename Xs, typename N>
  35. constexpr auto at_t::operator()(Xs&& xs, const N& n) const
  36. {
  37. using tag_type = tag_of<Xs>;
  38. using at_impl_type = at_impl<tag_type>;
  39. return at_impl_type::apply(std::forward<Xs>(xs), n);
  40. }
  41. }
  42. }
  43. }