std::mem_fun_ref
提供: cppreference.com
< cpp | utility | functional
ヘッダ <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)() ); |
(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( S (T::*f)(Arg) ); |
(2) | (C++11で非推奨) (C++17で削除) |
目的の型をテンプレート引数から推定して、メンバ関数ラッパーオブジェクトを作成します。 ラッパーオブジェクトはその operator() への第1引数として T
型のオブジェクトへの参照を期待します。
1) 実質的に std::mem_fun_ref_t<S,T>(f) または std::const_mem_fun_ref_t<S,T>(f) を呼びます。
2) 実質的に std::mem_fun1_ref_t<S,T>(f) または std::const_mem_fun1_ref_t<S,T>(f) を呼びます。
この関数および関連する型は、メンバ関数から呼び出し可能なアダプタ互換な関数オブジェクトを作成する、より汎用的な std::mem_fn および std::bind に導入に伴い、 C++11 で非推奨になり、 C++17 で削除されました。
目次 |
[編集] 引数
f | - | ラッパーを作成するメンバ関数へのポインタ |
[編集] 戻り値
f
をラップする関数オブジェクト。
[編集] 例外
処理系定義の例外が投げられるかもしれません。
[編集] ノート
std::mem_fun と std::mem_fun_ref の差は、前者はオブジェクトへのポインタ、後者は参照を期待する関数ラッパーを生成します。
[編集] 例
std::string のメンバ関数 size() を束縛するために std::mem_fun_ref
を使用します。
Run this code
#include <functional> #include <vector> #include <string> #include <iterator> #include <algorithm> #include <iostream> int main() { std::vector<std::string> v = {"once", "upon", "a", "time"}; std::transform(v.begin(), v.end(), std::ostream_iterator<std::size_t>(std::cout, " "), std::mem_fun_ref(&std::string::size)); }
出力:
4 4 1 4
[編集] 関連項目
(C++11で非推奨)(C++17で削除) |
メンバ関数ポインタから、オブジェクトへのポインタを使用して呼ぶことができるラッパーを作成します (関数テンプレート) |