std::ptr_fun
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <functional> で定義
|
||
template< class Arg, class Result > std::pointer_to_unary_function<Arg,Result> ptr_fun( Result (*f)(Arg) ); |
(1) | (C++11で非推奨) (C++17で削除) |
template< class Arg1, class Arg2, class Result > std::pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun( Result (*f)(Arg1, Arg2) ); |
(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 をラップする関数オブジェクト。
例外
(なし)
例
Run this code
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
bool isvowel(char c)
{
return std::string("aeoiuAEIOU").find(c) != std::string::npos;
}
int main()
{
std::string s = "Hello, world!";
std::copy_if(s.begin(), s.end(), std::ostreambuf_iterator<char>(std::cout),
std::not1(std::ptr_fun(isvowel)));
// C++11 alternatives:
// std::not1(std::cref(isvowel)));
// std::not1(std::function<bool(char)>(isvowel)));
// C++17 alternative:
// std::not_fn(isvowel));
}
出力:
Hll, wrld!