名前空間
変種
操作

operator==,!=(std::function)

From cppreference.com
< cpp‎ | utility‎ | functional‎ | function
 
 
ユーティリティライブラリ
言語サポート
型のサポート (基本型、RTTI)
ライブラリ機能検査マクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)  
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
 
関数オブジェクト
関数の呼び出し
(C++17)(C++23)
恒等関数オブジェクト
(C++20)
透過的な演算子ラッパー
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

古いバインダとアダプタ
(C++17まで*)
(C++17まで*)
(C++17まで*)
(C++17まで*)  
(C++17まで*)
(C++17*まで)(C++17*まで)(C++17*まで)(C++17*まで)
(C++20まで*)
(C++20まで*)
(C++17*まで)(C++17*まで)
(C++17*まで)(C++17*まで)

(C++17まで*)
(C++17*まで)(C++17*まで)(C++17*まで)(C++17*まで)
(C++20まで*)
(C++20まで*)
 
 
ヘッダ <functional> で定義
template< class R, class... ArgTypes >

bool operator==( const std::function<R(ArgTypes...)>& f,

                 std::nullptr_t ) noexcept;
(1) (C++11以降)
template< class R, class... ArgTypes >

bool operator==( std::nullptr_t,

                 const std::function<R(ArgTypes...)>& f ) noexcept;
(2) (C++11以降)
(C++20まで)
template< class R, class... ArgTypes >

bool operator!=( const std::function<R(ArgTypes...)>& f,

                 std::nullptr_t ) noexcept;
(3) (C++11以降)
(C++20まで)
template< class R, class... ArgTypes >

bool operator!=( std::nullptr_t,

                 const std::function<R(ArgTypes...)>& f ) noexcept;
(4) (C++11以降)
(C++20まで)

std::function をヌルポインタと比較します。空の関数(つまり、呼び出し可能なターゲットを持たない関数)は等しいと評価され、空でない関数は等しくないと評価されます。

!= 演算子は operator== から合成される。

(C++20以降)

目次

[編集] パラメータ

f - 比較する std::function

[編集] 戻り値

1,2) !f
3,4) (bool) f

[編集]

#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

[編集] 関連項目

std::move_only_functionnullptr を比較する
(関数) [編集]
English 日本語 中文(简体) 中文(繁體)