目录

forward_as_tuple

描述 (Description)

它构造一个元组对象,其中对args中元素的rvalue引用适合作为参数转发给函数。

声明 (Declaration)

以下是std :: forward_as_tuple的声明。

C++98

	
template<class... Types>
   tuple<Types&&...> forward_as_tuple (Types&&... args) noexcept;

C++11

template<class... Types>
   tuple<Types&&...> forward_as_tuple (Types&&... args) noexcept;

C++14

template<class... Types>
   constexpr tuple<Types&&...> forward_as_tuple (Types&&... args) noexcept;

参数 (Parameters)

args - 它包含构造的元组应包含的元素列表。

返回值 (Return Value)

它返回一个适当类型的元组对象来保存args。

异常 (Exceptions)

No-throw guarantee - 此成员函数永远不会抛出异常。

数据竞争 (Data races)

没有通过这个电话介绍。

例子 (Example)

在下面的示例中为std :: forward_as_tuple。

#include <iostream>
#include <tuple>
#include <string>
void print_pack (std::tuple<std::string&&,int&&> pack) {
   std::cout << std::get<0>(pack) << ", " << std::get<1>(pack) << '\n';
}
int main() {
   std::string str ("iowiki.com");
   print_pack (std::forward_as_tuple(str+" sairamkrishna",25));
   print_pack (std::forward_as_tuple(str+" Gopal",22));
   print_pack (std::forward_as_tuple(str+" Ram",30));
   return 0;
}

输出应该是这样的 -

iowiki.com sairamkrishna, 25
iowiki.com Gopal, 22
iowiki.com Ram, 30
↑回到顶部↑
WIKI教程 @2018