Namespaces
Variants

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

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until 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 을 null 포인터와 비교합니다. 빈 함수(즉, 호출 가능한 대상이 없는 함수)는 동일하게 비교되고, 비어 있지 않은 함수는 동일하지 않게 비교됩니다.

!= 연산자는 합성된 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) // 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

참고 항목

(C++23)
std::move_only_function nullptr 와 비교합니다
(함수)