std::forward_as_tuple
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| 在头文件 <tuple> 中定义
|
||
| template< class... Types > tuple<Types...> forward_as_tuple( Types&&... args ); |
(C++11 起) | |
构造一个元组中的参数
args适合作为函数的参数进行转发。该元组的右值引用的数据成员时,右值作为参数,否则有左值引用的数据成员。如果右值使用此功能前必须消耗的下一个序列点,结果.原文:
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. If rvalues are used, the result of this function must be consumed before the next sequence point.目录 |
[编辑] 参数
| args | - | 零个或多个参数来构造的元组
原文: zero or more arguments to construct the tuple from |
[编辑] 返回值
一个
std::tuple创建的对象,如果std::tuple<Types&&...>(std::forward<Types>(args)...)原文:
A
std::tuple object created as if by std::tuple<Types&&...>(std::forward<Types>(args)...)[编辑] 例外
[编辑] 示例
#include <iostream> #include <map> #include <tuple> #include <string> int main() { std::map<int, std::string> m; // same as m.emplace(10, 20, 'a'); m.emplace(std::forward_as_tuple(10, std::string(20, 'a'))); std::cout << "m[10] = " << m[10] << '\n'; // The following is an error: it produces a // std::tuple<int&&, std::string&&> holding two dangling references. // // auto t = std::forward_as_tuple(10, std::string(20, 'a')); // m.emplace(t); }
输出:
m[10] = aaaaaaaaaaaaaaaaaaaa
| 创建一个 tuple对象的参数类型定义的类型原文: creates a tuple object of the type defined by the argument types(函数模板) | |
创建一个tuple的左值引用或将一个元组拆开成多个个体对象 (函数模板) | |
通过连接任意数量的元组来创建一个tuple (函数模板) | |