jeudi 23 janvier 2020

How to choose between `push_*()` and `emplace_*()` functions?

I understand the difference between the two function variants.

My question is: should I normally use good old push_*() version and only switch to emplace_*() when my profiler tells me this will benefit performance (that is, do not optimise prematurely)? Or should I switch to using emplace_*() as the default (perhaps not to pessimise the code unnecessarily - similar to i++ vs ++i in for loops)?

Is any of the variants more universal than the other (that is, imposes less constraints on the type being inserted) in realistic non-contrived use cases?

Aucun commentaire:

Enregistrer un commentaire