std::forward_as_tuple
| ヘッダ <tuple>
|
||
template< class... Types >
std::tuple<Types&&...> forward_as_tuple( Types&&... args ) noexcept;
|
(C++11以上) (C++14からconstexpr) |
|
関数に引数として転送するのに適した、args内の引数への参照のタプルを構築します。右辺値が引数として使用された場合、タプルは右辺値参照のデータメンバを持ち、それ以外の場合は左辺値参照のデータメンバを持ちます。
パラメータ
| args | - | タプルを構築するための0個以上の引数 |
戻り値
A std::tuple オブジェクトは、以下のように作成されたかのように生成されます: std:: tuple < Types && ... > ( std:: forward < Types > ( args ) ... )
注記
引数が一時オブジェクトである場合、
forward_as_tuple
はその寿命を延長しません。それらは完全式の終了前に使用されなければなりません。
例
#include <iostream> #include <map> #include <string> #include <tuple> int main() { std::map<int, std::string> m; m.emplace(std::piecewise_construct, std::forward_as_tuple(6), std::forward_as_tuple(9, 'g')); std::cout << "m[6] = " << m[6] << '\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[6] = ggggggggg
関連項目
|
(C++11)
|
引数の型によって定義される型の
tuple
オブジェクトを作成する
(関数テンプレート) |
|
(C++11)
|
左辺値参照の
tuple
を作成する、またはtupleを個々のオブジェクトに展開する
(関数テンプレート) |
|
(C++11)
|
任意の数のtupleを連結して
tuple
を作成する
(関数テンプレート) |
|
(C++17)
|
引数のtupleで関数を呼び出す
(関数テンプレート) |