fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct smth
  7. {
  8. smth() { cout << "no args" << endl; }
  9. smth(int x) { cout << "with x = " << x << endl; }
  10. };
  11.  
  12. void fill_pb()
  13. {
  14. cout << "=== fill_pb ===" << endl;
  15.  
  16. vector <smth> v;
  17. for (int q=0; q<3; ++q) v.push_back(q);
  18.  
  19. cout << endl;
  20. }
  21.  
  22. void fill_eb()
  23. {
  24. cout << "=== fill_eb ===" << endl;
  25.  
  26. vector <smth> v;
  27. for (int q=0; q<3; ++q) v.emplace_back(q);
  28.  
  29. cout << endl;
  30. }
  31.  
  32. void fill_p(vector <int> p)
  33. {
  34. cout << "=== fill_p ===" << endl;
  35.  
  36. vector <smth> v(p.size());
  37. for (int q=0; q<p.size(); ++q) v[p[q]] = p[q];
  38.  
  39. cout << endl;
  40. }
  41.  
  42. int main()
  43. {
  44. fill_pb();
  45. fill_eb();
  46. fill_p({3,1,0,2});
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
=== fill_pb ===
with x = 0
with x = 1
with x = 2

=== fill_eb ===
with x = 0
with x = 1
with x = 2

=== fill_p ===
no args
no args
no args
no args
with x = 3
with x = 1
with x = 0
with x = 2