名前空間
変種
操作

std::reference_wrapper

提供: cppreference.com
< cpp‎ | utility‎ | functional

 
 
ユーティリティライブラリ
支援を入力します (basic types, RTTI, type traits)
動的なメモリ管理
エラー処理
プログラムユーティリティ
可変個引数関数
日付と時刻
関数オブジェクト
initializer_list(C++11)
bitset
hash(C++11)
関係演算子
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
ペアとタプル
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
フォワード、スワップ、および移動
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
関数オブジェクト
関数ラッパー
Original:
Function wrappers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
function(C++11)
mem_fn(C++11)
bad_function_call(C++11)
バインド
Original:
Bind
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
bind(C++11)
is_bind_expression(C++11)
is_placeholder(C++11)
_1, _2, _3, ...(C++11)
リファレンス·ラッパー
Original:
Reference wrappers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
reference_wrapper(C++11)
ref
cref
(C++11)
(C++11)
オペレーターのラッパー
Original:
Operator wrappers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
否定子
Original:
Negators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バインダーおよびアダプタは非推奨になりました
Original:
Deprecated binders and adaptors
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unary_function(廃止予定)
binary_function(廃止予定)
ptr_fun(廃止予定)
pointer_to_unary_function(廃止予定)
pointer_to_binary_function(廃止予定)
mem_fun(廃止予定)
mem_fun_t
mem_fun1_t
const_mem_fun_t
const_mem_fun1_t
(廃止予定)
(廃止予定)
(廃止予定)
(廃止予定)
mem_fun_ref(廃止予定)
mem_fun_ref_t
mem_fun1_ref_t
const_mem_fun_ref_t
const_mem_fun1_ref_t
(廃止予定)
(廃止予定)
(廃止予定)
(廃止予定)
binder1st
binder2nd
(廃止予定)
(廃止予定)
bind1st
bind2nd
(廃止予定)
(廃止予定)
 
std::reference_wrapper
メンバ関数
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
reference_wrapper::reference_wrapper
reference_wrapper::operator=
reference_wrapper::get
reference_wrapper::operator T&
reference_wrapper::operator()
 
Defined in header <functional>
template< class T >
class reference_wrapper;
(C++11およびそれ以降)
クラステンプレートstd::reference_wrapperは、オブジェクトまたはタイプCopyConstructibleの関数への参照の周りCopyAssignableTラッパーです。 std::reference_wrapperのインスタンスは、オブジェクト(コピーまたはコンテナに格納することができます)がありますが、それらは参照によって基になる型を取る関数で引数として使用することができるように、T&に暗黙的に変換可能です.
Original:
Class template 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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ヘルパー関数はstd::refstd::crefしばしばstd::reference_wrapperオブジェクトを生成するために使用され.
Original:
Helper functions std::ref and std::cref are often used to generate std::reference_wrapper objects.
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またstd::bindまたは参照によってstd::threadのコンストラクタにオブジェクトを渡すために使用され.
Original:
std::reference_wrapper is also used to pass objects to std::bind or to the constructor of std::thread by reference.
The text has been machine-translated via Google Translate.
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_typeA1.
である場合

T引数を取りませんクラスT0のメンバ関数へのポインタである場合、2)ならば、argument_typeT0*、多分CV-qualified
です

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 pointer to member function of class T0 that takes no arguments, then argument_type is T0*, possibly cv-qualified

3) if T is a class type with a member type T::argument_type, then argument_type is an alias of that
The 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つの引数を取る関数への関数ポインタである場合、またはA1A2、その後first_argument_typeA1.
です

T1つの引数を取るクラスT0のメンバ関数へのポインタである場合、2)ならば、first_argument_typeT0*、多分CV-qualified
です Tはメンバー型T::first_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 first_argument_type is A1.

2) if T is a pointer to member function of class T0 that takes one argument, then first_argument_type is T0*, possibly cv-qualified
3) if T is a class type with a member type T::first_argument_type, then first_argument_type is an alias of that

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つの引数を取る関数への関数ポインタである場合、またはA1A2、その後second_argument_typeA2.
です

2)T1引数T0を取るクラスA1のメンバ関数へのポインタは、次にsecond_argument_typeはおそらく、A1である場合CV-qualified

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 pointer to member function of class T0 that takes one argument A1, then second_argument_type is A1, possibly cv-qualified

3) if T is a class type with a member type T::second_argument_type, then first_argument_type is an alias of that
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:
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.

(パブリックメンバ関数) [edit]
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.

(パブリックメンバ関数) [edit]
格納された参照にアクセスします
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.

(パブリックメンバ関数) [edit]
格納された関数を呼び出します
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.

(パブリックメンバ関数) [edit]

[編集]

それが可能な複数の索引を使用して同じコンテナにアクセスできるようになります参照のコンテナとしてreference_wrapperの使用方法を示します
Original:
Demonstrates the use of reference_wrapper as a container of references, which makes it possible to access the same container using multiple indexes
The text has been machine-translated via Google Translate.
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';
}

Output:

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.

(関数テンプレート) [edit]
(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.

(関数テンプレート) [edit]