fork download
  1. #include <iostream>
  2. #include <tuple>
  3. #include <sstream>
  4.  
  5. template<int N>
  6. struct A
  7. {
  8. std::string data;
  9. A(std::istream & stream) { stream >> data; }
  10. friend std::ostream& operator<<(std::ostream & out, A<N> const & a)
  11. {
  12. return out << "A"<<N<<"::data = " << a.data;
  13. }
  14. };
  15. typedef A<1> A1;
  16. typedef A<2> A2;
  17.  
  18. template<typename ...Args>
  19. void test(std::istream & stream)
  20. {
  21. std::tuple<Args...> args { Args(stream)... };
  22. std::cout << std::get<0>(args) << std::endl;
  23. std::cout << std::get<1>(args) << std::endl;
  24. }
  25.  
  26. int main()
  27. {
  28. std::stringstream ss("A1 A2");
  29. test<A1,A2>(ss);
  30. }
Success #stdin #stdout 0s 3020KB
stdin
stdout
A1::data = A2
A2::data = A1