std:: ptr_fun
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<functional>
|
||
|
template
<
class
Arg,
class
Result
>
std::
pointer_to_unary_function
<
Arg,Result
>
|
(1) |
(C++11で非推奨)
(C++17で削除) |
|
template
<
class
Arg1,
class
Arg2,
class
Result
>
std::
pointer_to_binary_function
<
Arg1,Arg2,Result
>
|
(2) |
(C++11で非推奨)
(C++17で削除) |
関数ラッパーオブジェクト( std:: pointer_to_unary_function または std:: pointer_to_binary_function )を作成し、テンプレート引数から対象の型を推論します。
この関数および関連する型は、C++11以降、より汎用的な std::function および std::ref を推奨するため非推奨となりました。これらはいずれも、通常の関数から呼び出し可能なアダプタ互換の関数オブジェクトを生成します。
目次 |
パラメータ
| f | - | ラッパーを作成する関数へのポインタ |
戻り値
f をラップする関数オブジェクト。
例外
実装定義の例外をスローする可能性があります。
例
#include <algorithm> #include <functional> #include <iostream> #include <string_view> constexpr bool is_vowel(char c) { return std::string_view{"aeoiuAEIOU"}.find(c) != std::string_view::npos; } int main() { std::string_view s = "Hello, world!"; std::ranges::copy_if(s, std::ostreambuf_iterator<char>(std::cout), std::not1(std::ptr_fun(is_vowel))); #if 0 // C++11 alternatives: std::not1(std::cref(is_vowel))); std::not1(std::function<bool(char)>(is_vowel))); [](char c) { return !is_vowel(c); }); // C++17 alternatives: std::not_fn(is_vowel)); #endif }
出力:
Hll, wrld!
関連項目
|
(C++11)
|
任意のコピー構築可能な呼び出し可能オブジェクトのコピー可能ラッパー
(クラステンプレート) |
|
(C++23)
|
指定された呼び出しシグネチャで修飾子をサポートする任意の呼び出し可能オブジェクトのムーブ専用ラッパー
(クラステンプレート) |
|
(C++17)
(C++23)
|
任意の
Callable
オブジェクトを指定された引数で呼び出す
(戻り値の型を指定可能)
(C++23以降)
(関数テンプレート) |
|
(C++17)
|
保持する関数オブジェクトの結果の補数を返す関数オブジェクトを作成する
(関数テンプレート) |