Constructs a tuple of references to the arguments in args suitable for forwarding as an argument to a function. The tuple has rvalue reference data members when rvalues are used as arguments, and otherwise has lvalue reference data members.
[edit] Parameters args - zero or more arguments to construct the tuple from [edit] Return valueA std::tuple object created as if by std::tuple<Types&&...>(std::forward<Types>(args)...)
[edit] NotesIf the arguments are temporaries, forward_as_tuple
does not extend their lifetime; they have to be used before the end of the full expression.
#include <iostream> #include <map> #include <string> #include <tuple> int main() { std::map<int, std::string> m; m.emplace(std::piecewise_construct, std::forward_as_tuple(6), std::forward_as_tuple(9, 'g')); std::cout << "m[6] = " << m[6] << '\n'; // The following is an error: it produces a // std::tuple<int&&, char&&> holding two dangling references. // // auto t = std::forward_as_tuple(20, 'a'); // m.emplace(std::piecewise_construct, std::forward_as_tuple(10), t); }
Output:
[edit] See also creates atuple
object of the type defined by the argument types
tuple
by concatenating any number of tuples
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4