News for hackers. Stuff that matters.
Re:Don’t blindly prefer emplace_back to push_back by xKingfisher on Thursday March 04, 2021 @04:27AM (#26340389)
Not to mention the very real risk of accidently invoking the wrong constructor. If you change the type of a vector, push_back is a good deal safer than emplace_back.

Especially since many of the standard containers have many more constructors that you'd think - hello std::vector(size_type count).

Re:Don’t blindly prefer emplace_back to push_back by codeflo on Thursday March 04, 2021 @04:59AM (#26340594)
That’s one of my favorites as well. The fact that C++ will so happily auto-convert almost anything into an integer makes it even more likely to hit this accidentally.
Re:Don’t blindly prefer emplace_back to push_back by xKingfisher on Thursday March 04, 2021 @05:24AM (#26340755)
And explicit constructors won't save you from this one.
Re:Don’t blindly prefer emplace_back to push_back by rq1 on Thursday March 04, 2021 @04:35AM (#26340429)
Use Phantom Types. The compiler will help you.