fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include <iostream>
  4. #include <tuple>
  5. #include <vector>
  6. #include <utility>
  7.  
  8. struct Foo
  9. {
  10. Foo(std::tuple<int, float>)
  11. {
  12. std::cout << "Constructed a Foo from a tuple\n";
  13. }
  14.  
  15. Foo(int, float)
  16. {
  17. std::cout << "Constructed a Foo from an int and a float\n";
  18. }
  19. };
  20.  
  21. int main()
  22. {
  23. int one = 1;
  24. float pi = 3.14;
  25. std::tuple<int, float> t(one, pi);
  26. std::vector<Foo> vec;
  27. vec.push_back(Foo(t));
  28.  
  29. std::cout << "Creating p1...\n";
  30. // std::pair<Foo, Foo> p1(t, t);
  31. vec.emplace_back(one, pi);
  32.  
  33. std::cout << "Creating p2...\n";
  34. // std::pair<Foo, Foo> p2(std::piecewise_construct, t, t);
  35. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Constructed a Foo from a tuple
Creating p1...
Constructed a Foo from an int and a float
Creating p2...