- 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 <tuple>
#include <string>
#include <type_traits>
int main()
{
// 一時オブジェクトからは右辺値参照のtupleが作られる
auto t1 = std::forward_as_tuple(1, 'a', std::string("Hello"));
static_assert(std::is_same<decltype(t1), std::tuple<int&&, char&&, std::string&&>>());
// 左辺値からは左辺値参照のtupleが作られる
int a = 1;
char b = 'a';
std::string c = "Hello";
auto t2 = std::forward_as_tuple(a, b, c);
static_assert(std::is_same<decltype(t2), std::tuple<int&, char&, std::string&>>());
}
- std::forward_as_tuple[color ff0000]
- C++11
- Clang: ??
- GCC: 4.6.1 [mark verified]
- ICC: ??
- Visual C++:
forward_as_tuple
は、ドラフト仕様の段階でpack_arguments
という名前で一時期表記されていた。
コンパイラのバージョンによっては、この名前での実装もありえる。