emplace — constructs element in-place:
1std::vector<std::pair<int, std::string>> v;2v.emplace_back(1, "hello"); // constructs pair in-place
insert — copies/moves existing object:
1v.push_back({1, "hello"}); // constructs temporary, then moves
Performance difference:
emplace_back: one constructionpush_back: temporary + moveWhen emplace wins:
1std::set<std::string> s;2s.emplace("long string"); // one allocation3s.insert("long string"); // temporary + copy/move
Best practice: Default to emplace for non-trivial types.