Hacker News new | ask | show | jobs
by xKingfisher 1935 days ago
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).

2 comments

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.
And explicit constructors won't save you from this one.
Use Phantom Types. The compiler will help you.