首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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_functionstd::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::functionstd::ref,它们都从普通函数创建可调用适配器兼容的函数对象。

参数

f

-

pointer to a function to create a wrapper for

返回值

函数对象包装f...

例外

%280%29

二次

代码语言:javascript
复制
#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)));
 
}

二次

产出:

二次

代码语言:javascript
复制
Hll, wrld!

二次

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com