←back to thread

178 points todsacerdoti | 4 comments | | HN request time: 1.631s | source
1. xKingfisher ◴[] No.26340389[source]
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).

replies(2): >>26340429 #>>26340594 #
2. rq1 ◴[] No.26340429[source]
Use Phantom Types. The compiler will help you.
3. codeflo ◴[] No.26340594[source]
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.
replies(1): >>26340755 #
4. xKingfisher ◴[] No.26340755[source]
And explicit constructors won't save you from this one.