std:: forward_as_tuple
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Non-member functions | ||||
|
forward_as_tuple
|
||||
|
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(C++20)
|
||||
| Helper concepts | ||||
|
(C++23)
|
||||
| Helper classes | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Deduction guides (C++17) |
|
ヘッダーで定義
<tuple>
|
||
|
template
<
class
...
Types
>
std:: tuple < Types && ... > forward_as_tuple ( Types && ... args ) noexcept ; |
(C++11以降)
(constexprはC++14以降) |
|
引数 args への参照からなるtupleを構築します。このtupleは関数への引数として転送するために適しており、引数としてrvalueが使用された場合はrvalue参照データメンバを持ち、それ以外の場合はlvalue参照データメンバを持ちます。
目次 |
パラメータ
| 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で関数を呼び出す
(関数テンプレート) |