Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. using namespace std;
  2. template<typename T>
  3. void print(T&& val) {
  4.     cout << val << endl;
  5. }
  6.  
  7. template<typename T, typename... Args>
  8. void print(T&& val, Args&&... args) {
  9.     cout << val;
  10.     print(args...);
  11. }
  12.  
  13. template<typename Tuple, size_t... I>
  14. void print_tuple_impl(Tuple&& tup, /* THIS IS A BLOODY TYPE and will be unpacked! */ index_sequence<I...>) {
  15.     print(get<I>(tup)...);
  16. }
  17.  
  18. template<typename Tuple>
  19. void print_tuple(Tuple&& tup) {
  20.     using Indices = index_sequence<0, 2>;
  21.     /* Indices type allows to deduce size_t... in print_tuple_impl */
  22.     print_tuple_impl(tup, Indices{});
  23. }
  24.  
  25. int main() {
  26.     auto tup = make_tuple(5, 4.0, 13);
  27.     print_tuple(tup);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement