fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <tuple>
  4.  
  5. template<typename T, typename CharT>
  6. T extract(std::basic_istream<CharT>& is) {
  7. T val;
  8. is >> val;
  9. return val;
  10. }
  11.  
  12. void print(const std::tuple<int, long, double>& t) {
  13. using std::cout;
  14. cout << std::get<0>(t) << " " << std::get<1>(t) << " " << std::get<2>(t) << std::endl;
  15. }
  16.  
  17. int main()
  18. {
  19. std::stringstream ss1;
  20. std::stringstream ss2;
  21. ss1 << 1 << " " << 2 << " " << 3;
  22. ss2 << 1 << " " << 2 << " " << 3;
  23. auto compilerOrder = std::tuple<int, long, double>( extract<int>(ss1), extract<long>(ss1), extract<double>(ss1) );
  24. auto leftToRightOrder = std::tuple<int, long, double>{ extract<int>(ss2), extract<long>(ss2), extract<double>(ss2) };
  25. print(compilerOrder);
  26. print(leftToRightOrder);
  27. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
3 2 1
1 2 3