名前空間
変種
操作

std::mem_fn

提供: 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
(廃止予定)
(廃止予定)
 
Defined in header <functional>
template< class R, class T >
/*unspecified*/ mem_fn(R T::* pm);
(1) (C + + 11以来)
template< class R, class T, class... Args >

/*unspecified*/ mem_fn(R (T::* pm)(Args...));
template< class R, class T, class... Args >
/*unspecified*/ mem_fn(R (T::* pm)(Args...) const);
template< class R, class T, class... Args >
/*unspecified*/ mem_fn(R (T::* pm)(Args...) volatile);
template< class R, class T, class... Args >
/*unspecified*/ mem_fn(R (T::* pm)(Args...) const volatile);
template< class R, class T, class... Args >
/*unspecified*/ mem_fn(R (T::* pm)(Args...) &);
template< class R, class T, class... Args >
/*unspecified*/ mem_fn(R (T::* pm)(Args...) const &);
template< class R, class T, class... Args >
/*unspecified*/ mem_fn(R (T::* pm)(Args...) volatile &);
template< class R, class T, class... Args >
/*unspecified*/ mem_fn(R (T::* pm)(Args...) const volatile &);
template< class R, class T, class... Args >
/*unspecified*/ mem_fn(R (T::* pm)(Args...) &&);
template< class R, class T, class... Args >
/*unspecified*/ mem_fn(R (T::* pm)(Args...) const &&);
template< class R, class T, class... Args >
/*unspecified*/ mem_fn(R (T::* pm)(Args...) volatile &&);
template< class R, class T, class... Args >

/*unspecified*/ mem_fn(R (T::* pm)(Args...) const volatile &&);
(2) (C + 11が、欠陥)
関数テンプレートstd::mem_fn保存、コピーして、メンバへのポインタを呼び出すことができる、メンバへのポインタのラッパーオブジェクトを生成します。 std::mem_fnを呼び出すときに、オブジェクトへの両方の参照やポインタは(スマートポインタを含む)を使用することができます.
Original:
Function template std::mem_fn generates wrapper objects for pointers to members, which can store, copy, and invoke a pointer to member. Both references and pointers (including smart pointers) to an object can be used when invoking a std::mem_fn.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
オーバーロード(2)欠陥として報告されている.
Original:
The overloads (2) are reported as defect.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最近になって "一応レディ"に選ばれましたresolutionは、すべてのオーバーロード(2)を取り外しすることを提案している.
Original:
The resolution, which has recently been voted "Tentatively Ready" proposes to remove all the overloads (2).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
これはいくつかのコードを壊すことは、例3を参照してください.
Original:
This will break some code, see Example 3.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] 引数

pm -
ラップされるメンバへのポインタ
Original:
pointer to member that will be wrapped
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 戻り値

std::mem_fn、以下のメンバーを持つ型が指定されていない呼び出しラッパーを返します
Original:
std::mem_fn returns an call wrapper of unspecified type that has the following members:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

std::mem_fn
Original:
std::mem_fn
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
の戻り値

Member types

タイプ
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
result_type
pm場合pmの戻り値の型は、メンバーオブジェクトへのポインタに対して定義されていないメンバ関数へのポインタです
Original:
the return type of pm if pm is a pointer to member function, not defined for pointer to member object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
argument_type
T*、おそらくCV修飾、pmは、引数をとらないメンバ関数へのポインタである場合
Original:
T*, possibly cv-qualified, if pm is a pointer to member function taking no arguments
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
T*場合pmつの引数を取るメンバ関数へのポインタです
Original:
T* if pm is a pointer to member function taking one argument
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
T1場合pmタイプT1の引数を1つ取るメンバ関数へのポインタです
Original:
T1 if pm is a pointer to member function taking one argument of type T1
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

メンバ関数

operator()
省略可能なパラメータを、指定されたオブジェクト上のターゲットを呼び出します
Original:
invokes the target on a specified object, with optional parameters
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

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

[編集] 例外

なし.
Original:
None.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 例1

メンバ関数とメンバオブジェクトを格納し、実行するmem_fnを使用します
Original:
Use mem_fn to store and execute a member function and a member object:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <functional>
#include <iostream>
 
struct Foo {
  void display_greeting() {
    std::cout << "Hello, world.\n";
  }
  void display_number(int i) {
    std::cout << "number: " << i << '\n';
  }
  int data = 7;
};
 
int main() {
  Foo f;
 
  auto greet = std::mem_fn(&Foo::display_greeting);
  greet(f);
 
  auto print_num = std::mem_fn(&Foo::display_number);
  print_num(f, 42);
 
  auto access_data = std::mem_fn(&Foo::data);
  std::cout << "data: " << access_data(f) << '\n';
}

Output:

Hello, world.
number: 42
data: 7

[編集] 例2

数字のシーケンスを作成するstd::transformにメンバ関数を渡します
Original:
Pass a member function to std::transform to create a sequence of numbers:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <functional>
#include <iterator>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
 
int main()
{
    std::vector<std::string> words = {"This", "is", "a", "test"};
    std::vector<std::unique_ptr<std::string>> words2;
    words2.emplace_back(new std::string("another"));
    words2.emplace_back(new std::string("test"));
 
    std::vector<std::size_t> lengths;
    std::transform(words.begin(),
                   words.end(),
                   std::back_inserter(lengths),
                   std::mem_fn(&std::string::size)); // uses references to strings
    std::transform(words2.begin(),
                   words2.end(),
                   std::back_inserter(lengths),
                   std::mem_fn(&std::string::size)); // uses unique_ptr to strings
 
    std::cout << "The string lengths are ";
    for(auto n : lengths) std::cout << n << ' ';
    std::cout << '\n';
}

Output:

The string lengths are 4 2 1 4 7 4

[編集] 例3

#include <functional>
 
struct X {
  int x;
 
        int& easy()      {return x;}
        int& get()       {return x;}
  const int& get() const {return x;}
};
 
 
int main(void)
{
    auto a = std::mem_fn        (&X::easy); // no problem at all
//  auto b = std::mem_fn<int&  >(&X::get ); // no longer works with new specification
    auto c = std::mem_fn<int&()>(&X::get ); // works with both old and new specification
    auto d = [] (X& x) {return x.get();};   // another approach to overload resolution
}


[編集] も参照してください

(C++11)
指定された関数呼び出しシグネチャを持つ任意の型の呼び出し可能オブジェクトをラップします
Original:
wraps callable object of any type with specified function call signature
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]