Pack arguments in a tuple for assignment to a folly::emplace_iterator, folly::front_emplace_iterator, or folly::back_emplace_iterator. The iterator's operator= will unpack the tuple and pass the unpacked arguments to the container's emplace function, which in turn forwards the arguments to the (multi‐argument) constructor of the target class.
Synopsis
Declared in <folly/container/Iterator.h>
template<typename... Args>
emplace_args<Args...>
make_emplace_args(Args&&... args) noexcept(/* see-below */);
Description
Argument tuples generated with folly::make_emplace_args will be unpacked before being passed to the container's emplace function, even for iterators where implicit_unpack is set to false (so they will not implicitly unpack std::pair or std::tuple arguments to operator=).
Arguments are copied (lvalues) or moved (rvalues). To avoid copies and moves, wrap references using std::ref(), std::cref(), and folly::rref(). Beware of dangling references, especially references to temporary objects created with folly::rref().
Note that an argument pack created with folly::make_emplace_args is different from an argument pack created with std::make_pair or std::make_tuple. Specifically, passing a std::pair&& or std::tuple&& to an emplace iterator's operator= will pass rvalue references to all fields of that tuple to the container's emplace function, while passing an emplace_args&& to operator= will cast those field references to the exact argument types as passed to folly::make_emplace_args previously. If all arguments have been wrapped by std::reference_wrappers or folly::rvalue_reference_wrappers, the result will be the same as if the container's emplace function had been called directly (perfect forwarding), with no temporary copies of the arguments.
class Widget { Widget(int, int); }; std::vector<Widget> makeWidgets(const std::vector<int>& in) { std::vector<Widget> out; std::transform( in.begin(), in.end(), folly::back_emplacer(out), []i) { return folly::make_emplace_args(i, i); }); return out; }
Exception specification
This function is potentially-throwing unless noexcept(emplace_args<Args...>(std::forward<Args>(args)...)).
Return Value
An emplace_args holding the (decayed) arguments.
Parameters
Name |
Description |
args |
The arguments to pack into the emplace_args tuple. |
Created with MrDocs