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

Function objects

功能对象为其定义函数调用运算符的任何对象。C++提供了许多内置函数对象以及对新函数对象的创建和操作的支持。

多态函数包装器

std::function提供对存储任意函数对象的支持。

function (C++11)

wraps callable object of any type with specified function call signature (class template)

mem_fn (C++11)

creates a function object out of a pointer to a member (function template)

bad_function_call (C++11)

the exception thrown when invoking an empty std::function (class)

invoke (C++17)

invokes any Callable object with given arguments (function template)

绑定

std::bind提供对部分函数应用,即将参数绑定到函数以生成新函数。

bind (C++11)

binds one or more arguments to a function object (function template)

is_bind_expression (C++11)

indicates that an object is std::bind expression or can be used as one (class template)

is_placeholder (C++11)

indicates that an object is a standard placeholder or can be used as one (class template)

在命名空间std::占位符中定义

[医]1,[医]2,[医]3、[医]4,...%28C++11%29占位符用于std::binding表达式%28常数%29中的未绑定参数

否定词

std::not_fn创建一个函数对象,该对象否定传递给它的可调用对象的结果。

not_fn (C++17)

Creates a function object that returns the complement of the result of the function object it holds (function template)

unary_negate (deprecated)

wrapper function object returning the complement of the unary predicate it holds (class template)

binary_negate (deprecated)

wrapper function object returning the complement of the binary predicate it holds (class template)

not1 (deprecated)

constructs custom std::unary_negate object (function template)

not2 (deprecated)

constructs custom std::binary_negate object (function template)

搜索者

提供了实现几种字符串搜索算法的搜索器,可以直接使用,也可以与std::search...

default_searcher (C++17)

standard C++ library search algorithm implementation (class template)

boyer_moore_searcher (C++17)

Boyer-Moore search algorithm implementation (class template)

boyer_moore_horspool_searcher (C++17)

Boyer-Moore-Horspool search algorithm implementation (class template)

参考包装

引用包装器允许引用参数存储在可复制的函数对象中:

reference_wrapper (C++11)

CopyConstructible and CopyAssignable reference wrapper (class template)

refcref (C++11)(C++11)

creates a std::reference_wrapper with a type deduced from its argument (function template)

运算符函数对象

C++定义了几个函数对象,它们表示常见的算术和逻辑操作:

算术运算

*。

+函数对象实现x+y%28类模板%29

减号函数对象实现x-y%28类模板%29

实现x的乘法函数对象%2AY%28类模板%29

划分函数对象实现x/y%28类模板%29

模数函数对象实现x%y%28类模板%29

否定函数对象实现-x%28类模板%29

比较

平等[医]函数对象实现x==y%28类模板%29

不[医]平等[医]函数对象实现x%21=y%28类模板%29

实现x>y%28类模板%29的更大函数对象

减去实现x<y%28类模板%29的函数对象

更大[医]实现x>=y%28类模板%29的等函数对象

减[医]实现x<=y%28类模板%29的等函数对象

逻辑运算

逻辑[医]和函数对象实现x&y%28类模板%29

逻辑[医]或实现x的函数对象Y%28类模板%29

逻辑[医]非函数对象实现%21x%28类模板%29

按位运算

钻头[医]和函数对象实现x&y%28类模板%29

钻头[医]或实现x的函数对象Y%28类模板%29

钻头[医]XOR函数对象实现x^y%28类模板%29

钻头[医]非%28C++14%29函数对象实现~x%28类模板%29

旧粘合剂和适配器

一些提供早期功能支持的实用程序在C++11中被废弃,在C++17中被删除:

底座

*。

一元[医]函数%28,直到C++17%29适配器-兼容一元函数基类%28类模板%29

二进制[医]函数%28直到C++17%29适配器兼容二进制函数基类%28类模板%29

粘结剂

绑定1 stbinder2%28直到C++17%29%28直到C++17%29函数对象持有一个二进制函数和它的一个参数%28类模板%29

绑定1stbind2%28直到C++17%29%28直到C++17%29将一个参数绑定到二进制函数%28函数模板%29

功能适配器

指针[医]到[医]一元[医]函数%28,直到C++17%29适配器与指针指针的兼容包装器%28类模板%29

指针[医]到[医]二进制[医]函数%28,直到C++17%29适配器-兼容指针到二进制函数%28类模板%29的包装器

PTR[医]乐趣%28,直到C++17%29从指向函数%28的指针创建一个与适配器兼容的函数对象包装器%29。

米姆[医]乐趣[医]TMEM[医]漏斗1[医]康斯特[医]米姆[医]乐趣[医]康斯特[医]米姆[医]漏斗1[医]直到C++17%29%28直到C++17%29%28直到C++17%29%28直到C++17%29包装器用于指针指向髓或一元成员函数,可以用指针调用对象%28类模板%29

米姆[医]在C++17%29创建指向成员函数的指针的包装器之前,使用指向对象%28函数模板%29的指针调用

米姆[医]乐趣[医]参考文献[医]TMEM[医]漏斗1[医]参考文献[医]康斯特[医]米姆[医]乐趣[医]参考文献[医]康斯特[医]米姆[医]漏斗1[医]参考文献[医]直到C++17%29%28直到C++17%29%28直到C++17%29%28直到C++17%29包装器指针指向髓或一元成员函数,可以调用对象%28类模板%29

米姆[医]乐趣[医]在C++17%29创建指向成员函数的指针的包装器之前,引用对象%28函数模板%29调用

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

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

扫码关注腾讯云开发者

领取腾讯云代金券