Dec 18, 2014

[C++11] Emplacement vs. Insert


  • Emplacement most likely win if:
    • Value being added is constructed into the container , not assigned.
      • i.e The chunk of space has never being constructed before, i.e
        • vector.resize doesn't count, since resize default construct the spot with constructed type T
        • inserting in the middle, also not qualified.
    • Argument(s) passed are different from T.
      • i.e It's a Direct initialization from constructor, not copy constructor.
    • Value to be added is unlikely to be rejected as a duplicate.
      • i.e For unique key containers. Otherwise, it will first emplace construct the node, compare, and toss away the node since this key already exist in the container.
  • Insertion respects explicit constructor, emplacement does not.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.