News for hackers. Stuff that matters.
Re:Don’t blindly prefer emplace_back to push_back by pdpi on Thursday March 04, 2021 @04:44AM (#26340494)
Hence “blindly”. The blog post was a detailed, less sanctimonious version of your comment.
Re:Don’t blindly prefer emplace_back to push_back by IshKebab on Thursday March 04, 2021 @05:00AM (#26340605)
Yeah but the title sounds like "you shouldn't just always use emplace_back instead of push_back" but the actual content is "you shouldn't use emplace_back completely incorrectly because you don't know what it is".

The only actual argument against blindly using emplace_back everywhere is that it has worse compile time in a deliberately pathological microbenchmark. Not convincing, though it is interesting.

Re:Don’t blindly prefer emplace_back to push_back by TonyTrapp on Thursday March 04, 2021 @04:48AM (#26340514)
But then you could write a blog post about pretty much every API misuse ever, which doesn't really seem very constructive to me.

But okay, maybe it's more obvious when having worked with pre-C++11 code, where you would have killed for something like emplace_back. If you are new to the language and only know modern C++, you probably don't think much about why emplace_back exists in addition to push_back, and why it can be faster.

Re:Don’t blindly prefer emplace_back to push_back by xKingfisher on Thursday March 04, 2021 @05:20AM (#26340724)
Given the whole scanf/strlen thing going on, more blog posts about API pitfalls wouldn't necessarily be a bad thing.

And that is basically the premise of the Abseil Tip of the week series, which are an incredible resource for learning how to work with modern C++.

Re:Don’t blindly prefer emplace_back to push_back by pjmlp on Thursday March 04, 2021 @05:48AM (#26340893)
Given that some schools still teach C++ with Turbo C++ for MS-DOS, one cannot expect that everyone is up to date with CppCon C++Now talks.