Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <utility>
  4.  
  5. class W {
  6. public:
  7. W() { std::cout << "W()\n"; }
  8. W(int a) : a_(a) { std::cout << "W(int a)\n"; }
  9. int get_a() { return a_; }
  10. private:
  11. int a_;
  12. };
  13.  
  14. void foo_at(W bar) {
  15. std::map<int, W> map;
  16. map[0] = bar;
  17. }
  18.  
  19. void foo_insert(W bar) {
  20. std::map<int, W> map;
  21. map.insert(std::make_pair(0, bar));
  22. }
  23.  
  24. void foo_emplace(W bar) {
  25. std::map<int, W> map;
  26. map.emplace(std::make_pair(0, bar));
  27. }
  28.  
  29. int main() {
  30. std::cout << "foo_at\n";
  31. foo_at(W(10));
  32. std::cout << "foo_insert\n";
  33. foo_insert(W(10));
  34. std::cout << "foo_emplace\n";
  35. foo_emplace(W(10));
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement