(1) |
template <class Ret, class... Args> bool operator== (const function<Ret(Args...)>& lhs, nullptr_t rhs) noexcept; template <class Ret, class... Args> bool operator== (nullptr_t lhs, const function<Ret(Args...)>& rhs) noexcept; |
(2) |
template <class Ret, class... Args> bool operator!= (const function<Ret(Args...)>& lhs, nullptr_t rhs) noexcept; template <class Ret, class... Args> bool operator!= (nullptr_t lhs, const function<Ret(Args...)>& rhs) noexcept; |
// function comparisons vs nullptr #include <iostream> // std::cout #include <functional> // std::function, std::plus int main () { std::function<int(int,int)> foo = std::plus<int>(); std::function<int(int,int)> bar; std::cout << "foo is " << (foo==nullptr ? "not callable" : "callable") << ".\n"; std::cout << "bar is " << (bar==nullptr ? "not callable" : "callable") << ".\n"; return 0; } |
function::operator bool | 检查是否可调用(公共成员函数) |
function::target_type | 目标内部类型(公共成员函数) |