←back to thread

178 points todsacerdoti | 1 comments | | HN request time: 0.214s | source
Show context
forrestthewoods ◴[] No.26340404[source]
Weird article. In the first section the compiler (correctly, albeit unclearly) hints the student to write “widgets.emplace_back(foo, bar, baz);”.

The author then proceeds to compare widgets.push_back(std::move(w)); versus widgets.emplace_back(std::move(w));. Wat? Why is he comparing against the thing you aren’t supposed to write? That makes no sense.

The final section I can’t tell if he’s comparing compile-time or run-time. The comments make me think compile but I’m not sure?

Good topic for a blog post. But it feels like this post is sloppily mixing three different ideas. Very strange.

replies(1): >>26341087 #
1. lgeorget ◴[] No.26341087[source]
The author explains that people he's worked with when seeing a message from the compiler telling them to use emplace_back() instead of push_back() just replace "push_back" by "emplace_back" without changing the function arguments. And since the result makes the compiler happy they don't realize that this is not what the message told them to do.