I'm not quite sure if i can always replace push_back
with emplace_back
.
I know emplace_back
can forward the parameters to construct the object directly in the vector without copying twice (perfect forwarding etc...)
And if i do soemthing like this:
vector<A> o;
o.emplace_back(A{});
Then it should call the copy constructor of A. Correct ?
So it does exactly the same as push_back
. Doesn't it ?
Are there some exceptions? Are there good reasons to use push_back ? Because then it is easier to just use always emplace_back without thinking about it.
o.emplace_back();
. – Kerrek SBpush_back(value_type&& val)
so there's no need foremplace_back
temporaryA{}
. – 101010