std:: mem_fun_ref
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定義先ヘッダ
<functional>
|
||
|
template
<
class
Res,
class
T
>
std:: mem_fun_ref_t < Res,T > mem_fun_ref ( Res ( T :: * f ) ( ) ) ; |
(1) |
(C++11で非推奨)
(C++17で削除) |
|
template
<
class
Res,
class
T
>
std:: const_mem_fun_ref_t < Res,T > mem_fun_ref ( Res ( T :: * f ) ( ) const ) ; |
(1) |
(C++11で非推奨)
(C++17で削除) |
|
template
<
class
Res,
class
T,
class
Arg
>
std:: mem_fun1_ref_t < Res,T,Arg > mem_fun_ref ( Res ( T :: * f ) ( Arg ) ) ; |
(2) |
(C++11で非推奨)
(C++17で削除) |
|
template
<
class
Res,
class
T,
class
Arg
>
std:: const_mem_fun1_ref_t < Res,T,Arg > mem_fun_ref ( Res ( T :: * f ) ( Arg ) const ) ; |
(2) |
(C++11で非推奨)
(C++17で削除) |
メンバ関数のラッパーオブジェクトを作成し、テンプレート引数からターゲット型を推論します。ラッパーオブジェクトは、その
operator
(
)
の最初のパラメータとして、型
T
のオブジェクトへの参照を期待します。
この関数と関連する型はC++11で非推奨となり、C++17で削除されました。より汎用的な std::mem_fn および std::bind に置き換えられました。これらはいずれも、メンバ関数から呼び出し可能なアダプタ互換の関数オブジェクトを作成します。
目次 |
パラメータ
| f | - | ラッパーを作成するメンバー関数へのポインタ |
戻り値
f をラップする関数オブジェクト。
例外
実装定義の例外をスローする可能性があります。
注記
std:: mem_fun と std :: mem_fun_ref の違いは、前者がオブジェクトへのポインタを期待する関数ラッパーを生成するのに対し、後者は参照を期待する点です。
例
std::mem_fun_ref
を使用して、
std::string
のメンバー関数
size()
をバインドします。
#include <algorithm> #include <functional> #include <iostream> #include <iterator> #include <string> #include <vector> int main() { std::vector<std::string> v = {"once", "upon", "a", "time"}; std::transform(v.cbegin(), v.cend(), std::ostream_iterator<std::size_t>(std::cout, " "), std::mem_fun_ref(&std::string::size)); }
出力:
4 4 1 4
関連項目
|
(C++11で非推奨)
(C++17で削除)
|
メンバ関数へのポインタから、オブジェクトへのポインタで呼び出し可能なラッパーを作成する
(関数テンプレート) |