All challenges
Multiple ChoiceBeginner 45s

Emplace_back vs push_back

What is the key advantage of `v.emplace_back(args...)` over `v.push_back(T(args...))`?
Options
  1. 1It constructs the element in place from the args, avoiding a temporary (and thus a move).
  2. 2It always reallocates the vector first for safety, so the new element is never built in a stale buffer.
  3. 3It runs in O(log n) instead of amortized O(1), because it locates the insertion point by binary search.
  4. 4It bypasses copy elision for non-movable types, forcing a copy where push_back would have elided one.

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle