共用方式為


<functional> 運算子

operator==

測試可呼叫的物件是否是空的。

template <class Fty>
    bool operator==(const function<Fty>& f, null_ptr_type npc);

template <class Fty>
    bool operator==(null_ptr_type npc, const function<Fty>& f);

參數


要包裝的函式類型。

f
函式物件

全國 人大
Null 指標。

備註

運算子同時使用是 function 物件之參考的引數以及是 Null 指標常數的引數。 兩者都只有在 function 物件為空時,才會傳回 true。

範例

// std__functional__operator_eq.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 << "empty == "
        << (fn0 == 0) << std::endl;

    std::function<int(int)> fn1(neg);
    std::cout << std::boolalpha << "empty == "
        << (fn1 == 0) << std::endl;

    return (0);
}
empty == true
empty == false

operator!=

測試可呼叫的物件是否不是空的。

template <class Fty>
    bool operator!=(const function<Fty>& f, null_ptr_type npc);

template <class Fty>
    bool operator!=(null_ptr_type npc, const function<Fty>& f);

參數


要包裝的函式類型。

f
函式物件

全國 人大
Null 指標。

備註

運算子同時使用是 function 物件之參考的引數以及是 Null 指標常數的引數。 兩者都只有在 function 物件不是空的時,才會傳回 true。

範例

// std__functional__operator_ne.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 == "
        << (fn0 != 0) << std::endl;

    std::function<int (int)> fn1(neg);
    std::cout << std::boolalpha << "not empty == "
        << (fn1 != 0) << std::endl;

    return (0);
    }
not empty == false
not empty == true