3 ms·
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_
by xKingfisher 6y 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).
- rq1 6y agoUse Phantom Types. The compiler will help you.
- codeflo 6y agoThat’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.
- xKingfisher 6y agoAnd explicit constructors won't save you from this one.