function::operator unspecified
測試,如果儲存可呼叫的物件。
operator unspecified();
備註
運算子會傳回可以轉換為具有true值的 bool 的值時,只有在物件不是空的。 您可以使用它來測試物件是否空白。
範例
// std_tr1__functional__function_operator_bool.cpp
// compile with: /EHsc
#include <functional>
#include <iostream>
int neg(int val)
{
return (-val);
}
int main()
{
std::function<int (int)> fn0;
std::cout << std::boolalpha << "not empty == " << (bool)fn0 << std::endl;
std::function<int (int)> fn1(neg);
std::cout << std::boolalpha << "not empty == " << (bool)fn1 << std::endl;
return (0);
}
需求
標題: <functional>
命名空間: std