std::ptr_fun
From cppreference.com
< cpp | utility | functional
| ヘッダ <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)を作成します。ターゲット型はテンプレート引数から推論されます。
1) 実質的に std::pointer_to_unary_function<Arg,Result>(f) を呼び出します。
2) 実質的に std::pointer_to_binary_function<Arg1,Arg2,Result>(f) を呼び出します。
この関数および関連する型は、プレーンな関数から呼び出し可能なアダプター互換の関数オブジェクトを作成する、より汎用的な std::function および std::ref のために C++11 で非推奨となりました。
目次 |
[編集] パラメータ
| 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) |
保持する関数オブジェクトの結果の補数を返す関数オブジェクトを作成する (関数テンプレート) |