Do std library `emplace` functions make use of `std::in_place` tag

Viewed 102

I want to know whether C++ standard library emplace functions make use of std::in_place tags (to indicate that the contained object should be constructed in-place)? Because emplace function got introduced in c++11 and std::in_place in c++17.

1 Answers

The entire point of emplace and its ilk is to indicate that the object is being constructed in-place. The implementation isn't allowed to construct the item and copy/move it to its final location.

The main reason in_place is used in constructors is because constructors have to use overload resolution to tell which constructor you intend to call (for any and variant, they also specify the object type to construct as a template argument, since you can't provide template arguments to constructors outside of template argument deduction). So if you want to have something like the push_back/emplace_back distinction in a constructor, you have to do it with a parameter, not a function name.

Related