fork download
  1. #include <utility>
  2. #include <tuple>
  3.  
  4. template<typename T>
  5. struct unqualified {
  6. typedef typename std::remove_cv< typename std::remove_reference<T>::type>::type type;
  7. };
  8.  
  9. template <int...>
  10. struct indices_list { typedef indices_list type; };
  11.  
  12. template <int N, int... I>
  13. struct indices : indices<N-1, N-1, I...> { };
  14.  
  15. template <int... I>
  16. struct indices<0, I...> : indices_list<I...>{ };
  17.  
  18. template <typename T>
  19. struct tuple_indices : indices<std::tuple_size<typename unqualified<T>::type>::value> { };
  20.  
  21. template <int ...I, int ...J, typename Tuple0, typename Tuple1>
  22. auto awesome_tuple_dog( indices_list<I...>, indices_list<J...>, Tuple0&& t0, Tuple1&& t1 ) {
  23. return std::make_tuple( std::get<I>( std::forward<Tuple0>(t0) )..., std::get<J>( std::forward<Tuple1>(t1) )... );
  24. }
  25.  
  26. template <typename Tuple0, typename Tuple1>
  27. auto awesome_tuple_cat( Tuple0&& t0, Tuple1&& t1 ) {
  28. return awesome_tuple_dog( tuple_indices<Tuple0>(), tuple_indices<Tuple1>(), std::forward<Tuple0>( t0 ), std::forward<Tuple1>( t1 ) );
  29. }
  30.  
  31. int main () {
  32. std::tuple<bool, char> a;
  33. std::tuple<short, int> b;
  34. struct {} _ = awesome_tuple_cat( a, b );
  35.  
  36. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:22:90: warning: ‘awesome_tuple_dog’ function uses ‘auto’ type specifier without trailing return type [enabled by default]
 auto awesome_tuple_dog( indices_list<I...>, indices_list<J...>, Tuple0&& t0, Tuple1&& t1 ) {
                                                                                          ^
prog.cpp:27:50: warning: ‘awesome_tuple_cat’ function uses ‘auto’ type specifier without trailing return type [enabled by default]
 auto awesome_tuple_cat( Tuple0&& t0, Tuple1&& t1 ) {
                                                  ^
prog.cpp: In function ‘int main()’:
prog.cpp:34:43: error: conversion from ‘std::tuple<bool, char, short int, int>’ to non-scalar type ‘main()::<anonymous struct>’ requested
     struct {} _ = awesome_tuple_cat( a, b );
                                           ^
stdout
Standard output is empty