Advertisement
frasl

Untitled

Feb 15th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. template<unsigned n>
  2. struct Arg {
  3.  template<class X, class...Xs>
  4.  constexpr auto operator()(X x, Xs...xs) {
  5.    return Arg<n - 1>{}(xs...);
  6.  }
  7. };
  8.  
  9. template<>
  10. struct Arg<0> {
  11.  template<class X, class...Xs>
  12.  constexpr auto operator()(X x, Xs...) {
  13.    return x;
  14.  }
  15. };
  16.  
  17. template<unsigned n>
  18.  
  19. constexpr auto arg = Arg<n>{};
  20.  
  21. // arg<2>(0, 1, 2, 3, 4, 5) == 2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement