名前空間
変種
操作

「cpp/utility/tuple/forward as tuple」の版間の差分

提供: cppreference.com
< cpp‎ | utility‎ | tuple
(1版:Translate from the English version)
 
(2人の利用者による、間の3版が非表示)
1行: 1行:
{{tr_note}}
 
 
{{cpp/title|forward_as_tuple}}
 
{{cpp/title|forward_as_tuple}}
 
{{cpp/utility/tuple/navbar}}
 
{{cpp/utility/tuple/navbar}}
{{ddcl list begin}}
+
{{begin}}
{{ddcl list header | tuple}}
+
{{header | tuple}}
{{ddcl list item | notes={{mark since c++11}} | 1=
+
{{| notes={{mark since c++}} | 1=
 
template< class... Types >
 
template< class... Types >
tuple<Types...> forward_as_tuple( Types&&... args );
+
tuple<Types...> forward_as_tuple( Types&&... args ) ;
 
}}
 
}}
{{ddcl list end}}
+
{{end}}
  
{{tr|関数への引数として転送するのに適し{{tt|args}}の引数への参照のタプルを構築します。タプルは右辺値が引数として使用されているとき右辺値参照データメンバを持つ、それ以外は左辺値参照データメンバを持っています。右辺値が使用されている場合、この関数の結果は次のシーケンスポイントの前に消費しなければならない.|Constructs a tuple of references to the arguments in {{tt|args}} suitable for forwarding as an argument to a function. The tuple has rvalue reference data members when rvalues are used as arguments, and otherwise has lvalue reference data members. If rvalues are used, the result of this function must be consumed before the next sequence point.}}
+
{{tt|args}}
  
===パラメータ===
+
======
{{param list begin}}
+
{{begin}}
{{param list item | args |{{tr| からタプルを構築するためにゼロ個以上の引数| zero or more arguments to construct the tuple from}}}}
+
{{| args | }}
{{param list end}}
+
{{end}}
  
===値を返します===
+
======
{{tr|{{cpp/ltt|cpp/utility/tuple}}オブジェクトは{{c|std::tuple<Types&&...>(std::forward<Types>(args)...)}}たかのように作成しました|A {{cpp/ltt|cpp/utility/tuple}} object created as if by {{c|std::tuple<Types&&...>(std::forward<Types>(args)...)}}}}
+
{{c|std::tuple<Types&&...>(std::forward<Types>(args)...)}} {{|std::tuple}}
  
===例外===
+
======
{{noexcept}}
+
{{}}
  
 
===例===
 
===例===
35行: 34行:
 
     std::map<int, std::string> m;
 
     std::map<int, std::string> m;
  
     // same as m.emplace(10, 20, 'a');
+
     m.emplace(,
    m.emplace(std::forward_as_tuple(10, std::string(20, 'a')));
+
std::forward_as_tuple(10,
 +
std::(20, 'a'));
 
     std::cout << "m[10] = " << m[10] << '\n';
 
     std::cout << "m[10] = " << m[10] << '\n';
  
 
     // The following is an error: it produces a
 
     // The following is an error: it produces a
     // std::tuple<int&&, std::string&&> holding two dangling references.
+
     // std::tuple<int&&, &&> holding two dangling references.
 
     //
 
     //
     // auto t = std::forward_as_tuple(10, std::string(20, 'a'));
+
     // auto t = std::forward_as_tuple(20, 'a');
     // m.emplace(t);
+
     // m.emplace(t);
 
}
 
}
 
  | output=
 
  | output=
49行: 49行:
 
}}
 
}}
  
{{dcl list begin}}
+
{{dcl list template | cpp/utility/tuple/dcl list make_tuple}}
+
{{begin}}
{{dcl list template | cpp/utility/tuple/dcl list tie}}
+
{{| cpp/utility/tuple/make_tuple}}
{{dcl list template | cpp/utility/tuple/dcl list tuple_cat}}
+
{{| cpp/utility/tuple/tie}}
{{dcl list end}}
+
{{| cpp/utility/tuple/tuple_cat}}
 +
{{
 +
end}}
 +
 
 +
 +
 +
 +
 +
 +
 +
 +

2018年9月5日 (水) 05:25時点における最新版

 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
std::tuple
メンバ関数
非メンバ関数
forward_as_tuple
(C++20未満)(C++20未満)(C++20未満)(C++20未満)(C++20未満)(C++20)
推定ガイド(C++17)
ヘルパークラス
 
ヘッダ <tuple> で定義
template< class... Types >
tuple<Types&&...> forward_as_tuple( Types&&... args ) noexcept;
(C++11以上)
(C++14以上ではconstexpr)

関数に引数として転送するのに適した args 内の引数を指す参照のタプルを構築します。 タプルは引数として右辺値が使用される場合は右辺値参照のデータメンバを持ち、そうでなければ左辺値参照のデータメンバを持ちます。

目次

[編集] 引数

args - タプルを構築するための0個以上の引数

[編集] 戻り値

std::tuple<Types&&...>(std::forward<Types>(args)...) によって作成されたかのような std::tuple オブジェクト。

[編集] ノート

引数が一時オブジェクトの場合、 forward_as_tuple はその生存期間を延長しません。 それらは完全式の終了前に使用されなければなりません。

[編集]

#include <iostream>
#include <map>
#include <tuple>
#include <string>
 
int main()
{
    std::map<int, std::string> m;
 
    m.emplace(std::piecewise_construct,
              std::forward_as_tuple(10),
              std::forward_as_tuple(20, 'a'));
    std::cout << "m[10] = " << m[10] << '\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[10] = aaaaaaaaaaaaaaaaaaaa

[編集] 関連項目

引数の型によって定義される型の tuple オブジェクトを作成します
(関数テンプレート) [edit]
左辺値参照の tuple を作成したり、タプルを個々のオブジェクトに分解したりします
(関数テンプレート) [edit]
任意の数のタプルを連結して新たな tuple を作成します
(関数テンプレート) [edit]
(C++17)
タプルを引数として使用して関数を呼びます
(関数テンプレート) [edit]