std::reference_wrapper
![]() |
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
Defined in header <functional>
|
||
template< class T > class reference_wrapper; |
(C++11およびそれ以降) | |
std::reference_wrapper
は、オブジェクトまたはタイプCopyConstructible
の関数への参照の周りCopyAssignable
とT
ラッパーです。 std::reference_wrapper
のインスタンスは、オブジェクト(コピーまたはコンテナに格納することができます)がありますが、それらは参照によって基になる型を取る関数で引数として使用することができるように、T&に暗黙的に変換可能です.std::reference_wrapper
is a CopyConstructible
and CopyAssignable
wrapper around a reference to object or reference to function of type T
. Instances of std::reference_wrapper
are objects (can be copied or stored in containers), but they are implicitly convertible to T&, so that they can be used as arguments with the functions that take the underlying type by reference.You can help to correct and verify the translation. Click here for instructions.
std::reference_wrapper
オブジェクトを生成するために使用され. std::reference_wrapper
objects. You can help to correct and verify the translation. Click here for instructions.
std::reference_wrapper
またstd::bindまたは参照によってstd::threadのコンストラクタにオブジェクトを渡すために使用され.std::reference_wrapper
is also used to pass objects to std::bind or to the constructor of std::thread by reference.You can help to correct and verify the translation. Click here for instructions.
目次 |
[編集] メンバータイプ
タイプ
Original: type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
definition |
type
|
T
|
result_type
|
T 場合T の戻り値の型は関数です。それ以外の場合は、定義されていません Original: The return type of T if T is a function. Otherwise, not defined The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
argument_type
|
1)
T その後、型A1 の1つの引数を取る関数への関数やポインタはargument_type A1 .である場合
T はメンバー型T::argument_type 持つクラス型である場合3)、その後argument_type はそれのエイリアスですOriginal: 1) if T is a function or pointer to function that takes one argument of type A1 , then argument_type is A1 .2) if T is a class type with a member type T::argument_type , then argument_type is an alias of thatThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
first_argument_type
|
1)
T がタイプSの2つの引数を取る関数への関数ポインタである場合、またはA1 とA2 、その後first_argument_type はA1 .です
Original: 1) if T is a function or pointer to function that takes two arguments of type s A1 and A2 , then first_argument_type is A1 .2) if The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
second_argument_type
|
1)
T がタイプSの2つの引数を取る関数への関数ポインタである場合、またはA1 とA2 、その後second_argument_type はA2 .です 2) T はメンバー型T::second_argument_type 持つクラス型である場合3)、その後first_argument_type はそれのエイリアスですOriginal: 1) if T is a function or pointer to function that takes two arguments of type s A1 and A2 , then second_argument_type is A2 .2) if T is a class type with a member type T::second_argument_type , then first_argument_type is an alias of thatThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[編集] メンバ関数
新しいstd::reference_wrapperオブジェクトに参照を格納します Original: stores a reference in a new std::reference_wrapper object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
std::reference_wrapperを再バインドします Original: rebinds a std::reference_wrapper The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
格納された参照にアクセスします Original: accesses the stored reference The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
格納された関数を呼び出します Original: calls the stored function The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) |
[編集] 例
You can help to correct and verify the translation. Click here for instructions.
#include <algorithm> #include <list> #include <vector> #include <iostream> #include <functional> int main() { std::list<int> l = {-4, -3, -2, -1, 0, 1, 2, 3, 4}; std::vector<std::reference_wrapper<int>> v(l.begin(), l.end()); std::random_shuffle(v.begin(), v.end()); std::vector<std::reference_wrapper<int>> v2(v.begin(), v.end()); std::partition(v2.begin(), v2.end(), [](int n){return n<0;}); std::cout << "Contents of the list: "; for(int n: l) { std::cout << n << ' '; } std::cout << '\n'; std::cout << "Contents of the list, shuffled: "; for(int i: v) { std::cout << i << ' '; } std::cout << '\n'; std::cout << "Shuffled elements, partitioned: "; for(int i: v2) { std::cout << i << ' '; } std::cout << '\n'; }
出力:
Contents of the list: -4 -3 -2 -1 0 1 2 3 4 Contents of the list, shuffled: 0 -1 3 4 -4 1 -2 -3 2 Shuffled elements, partitioned: -3 -1 -2 -4 4 1 3 0 2
[編集] も参照してください
(C++11) (C++11) |
その引数から推論型でstd::reference_wrapperを作成します Original: creates a std::reference_wrapper with a type deduced from its argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) |
(C++11) |
関数オブジェクトに1つ以上の引数をバインドします Original: binds one or more arguments to a function object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) |