operators (std::function)
运算符=,%21=%28std::函数%29
template< class R, class... ArgTypes > bool operator==( const std::function | (1) | (since C++11) |
---|---|---|
template< class R, class... ArgTypes > bool operator==( std::nullptr_t, const std::function<R(ArgTypes...)>& f | (2) | (since C++11) |
template< class R, class... ArgTypes > bool operator!=( const std::function<R(ArgTypes...)>& f, std::nullptr_t | (3) | (since C++11) |
template< class R, class... ArgTypes > bool operator!=( std::nullptr_t, const std::function<R(ArgTypes...)>& f | (4) | (since C++11) |
比较std::function
带空指针。空函数%28,即没有可调用目标的函数%29比较相等,非空函数比较非相等。
参数
f | - | std::function to compare |
---|
返回值
1-2%29!f
3-4%29(bool) f
例外
noexcept
规格:
noexcept
例
二次
#include <functional>
#include <iostream>
using SomeVoidFunc = std::function<void(int)>;
class C {
public:
C(SomeVoidFunc void_func = nullptr) :
void_func_(void_func)
{
if (void_func_ == nullptr) { // specialized compare with nullptr
void_func_ = std::bind(&C::default_func, this, std::placeholders::_1
}
void_func_(7
}
void default_func(int i) { std::cout << i << '\n'; };
private:
SomeVoidFunc void_func_;
};
void user_func(int i)
{
std::cout << (i + 1) << '\n';
}
int main()
{
C c1;
C c2(user_func
}
二次
产出:
二次
7
8
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
http://en.cpPreference.com/w/cpp/实用程序/FunctionalFunctioner/Operator[医]CMP