Advertisement
Rochet2

SequenceGenerator.cpp

Jun 4th, 2018
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #ifndef _SEQUENCE_GENERATOR_H
  2. #define _SEQUENCE_GENERATOR_H
  3.  
  4. /*
  5. // Usage
  6.  
  7. template<int ...S, typename ...T>
  8. void Print(seq<S...> const &, std::tuple<T...> const & t)
  9. {
  10.     using expander = int[]; expander{(std::cout.operator<<(std::get<S>(t)), 0)...};
  11.     std::cout << std::endl;
  12. }
  13.  
  14. template<typename ...T>
  15. void Print(std::tuple<T...>const& t)
  16. {
  17.     static typename gens<sizeof...(T)>::type idx;
  18.     Print(idx, t);
  19. }
  20.  
  21. Print(std::make_tuple(123));
  22.  
  23. */
  24.  
  25. template<int ...>
  26. struct seq { };
  27. template<int N, int ...S>
  28. struct gens : gens<N - 1, N - 1, S...> { };
  29. template<int ...S>
  30. struct gens<0, S...> {
  31.     typedef seq<S...> type;
  32. };
  33.  
  34. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement