std::ptr_fun
Defined in header <functional> | | |
|---|---|---|
template< class Arg, class Result > std::pointer_to_unary_function<Arg,Result> ptr_fun( Result (*f)(Arg) ); | (1) | (until C++17)(deprecated since C++11) |
template< class Arg1, class Arg2, class Result > std::pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun( Result (*f)(Arg1, Arg2) ); | (2) | (until C++17)(deprecated since C++11) |
创建函数包装对象%28std::pointer_to_unary_function或std::pointer_to_binary_function%29,从模板参数推断目标类型。
1%29有效呼叫std::pointer_to_unary_function<Arg,Result>(f)...
2%29有效呼叫std::pointer_to_binary_function<Arg1,Arg2,Result>(f)...
这个函数和相关类型在C++11中被取消,而更倾向于更一般的std::function和std::ref,它们都从普通函数创建可调用适配器兼容的函数对象。
参数
f | - | pointer to a function to create a wrapper for |
|---|
返回值
函数对象包装f...
例外
%280%29
例
二次
#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)));
}二次
产出:
二次
Hll, wrld!二次
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

