- tuple[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp11[meta cpp]
namespace {
template <class... Types>
tuple<Types&&...> forward_as_tuple(Types&&...) noexcept; // C++11
template <class... Types>
constexpr tuple<Types&&...> forward_as_tuple(Types&&...) noexcept; // C++14
}
パラメータの元の型からなるtuple
を生成する。左辺値参照型は左辺値参照型として、右辺値は右辺値参照として転送される。
パラメータの元の型からなるtuple
オブジェクト
投げない
#include <iostream>
#include <tuple>
#include <string>
int main()
{
// 一時オブジェクトからは右辺値参照のtupleが作られる
std::tuple<int&&, char&&, std::string&&> t1 = std::forward_as_tuple(1, 'a', std::string("Hello"));
// 左辺値からは左辺値参照のtupleが作られる
int a = 1;
char b = 'a';
std::string c = "Hello";
std::tuple<int&, char&, std::string&> t2 = std::forward_as_tuple(a, b, c);
}
- std::forward_as_tuple[color ff0000]
- std::tuple[link tuple.md]
- C++11
- Clang: ??
- GCC: 4.6.1
- ICC: ??
- Visual C++:
forward_as_tuple
は、ドラフト仕様の段階でpack_arguments
という名前で一時期表記されていた。
コンパイラのバージョンによっては、この名前での実装もありえる。