std::forward_as_tuple
STD:向前[医]如[医]元组
Defined in header | | |
---|---|---|
template< class... Types > tuple<Types&&...> forward_as_tuple( Types&&... args | | (since C++11) (until C++14) |
template< class... Types > constexpr tuple<Types&&...> forward_as_tuple( Types&&... args | | (since C++14) |
中的参数的引用的元组。args
适合于作为参数转发给函数。当rvalue用作参数时,元组具有rvalue引用数据成员,否则具有lvalue引用数据成员。
参数
args | - | zero or more arguments to construct the tuple from |
---|
返回值
阿std::tuple对象创建的std::tuple<Types&&...>(std::forward<Types>(args)...)...
例外
noexcept
规格:
noexcept
注记
如果争论是暂时的,forward_as_tuple
不能延长它们的生命周期;它们必须在完整表达式结束前使用。
例
二次
#include <iostream>
#include <map>
#include <tuple>
#include <string>
int main()
{
std::map<int, std::string> m;
m.emplace(std::piecewise_construct,
std::forward_as_tuple(10),
std::forward_as_tuple(20, 'a')
std::cout << "m[10] = " << m[10] << '\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
}
二次
产出:
二次
m[10] = aaaaaaaaaaaaaaaaaaaa
二次
另见
make_tuple | creates a tuple object of the type defined by the argument types (function template) |
---|---|
tie | creates a tuple of lvalue references or unpacks a tuple into individual objects (function template) |
tuple_cat | creates a tuple by concatenating any number of tuples (function template) |
apply (C++17) | calls a function with a tuple of arguments (function template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
http://en.cpPreference.com/w/cpp/实用程序/tuple/Forward[医]如[医]元组