Namespaces
Variants

operator== (std::move_only_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* )
friend bool operator == ( const std:: move_only_function & f, std:: nullptr_t ) noexcept ;
(C++23 이후)

래퍼 f 가 호출 가능한 대상을 가지고 있는지 여부를 std::nullptr_t 와 형식적으로 비교하여 확인합니다. 빈 래퍼(즉, 대상이 없는 래퍼)는 동일하게 비교되고, 비어 있지 않은 함수들은 동일하지 않게 비교됩니다.

이 함수는 일반적인 unqualified lookup 또는 qualified lookup 으로는 보이지 않으며, std::move_only_function<FunctionType> 가 인자들의 연관 클래스일 때에만 argument-dependent lookup 에 의해서만 찾을 수 있습니다.

!= 연산자는 합성된 operator== 로부터 생성됩니다.

목차

매개변수

f - std::move_only_function 비교 대상

반환값

! f .

예제

#include <functional>
#include <iostream>
#include <utility>
using SomeVoidFunc = std::move_only_function<void(int) const>;
class C {
public:
    C() = default;
    C(SomeVoidFunc func) : void_func_(std::move(func)) {}
    void default_func(int i) const { std::cout << i << '\n'; };
    void operator()() const
    {
        if (void_func_ == nullptr) // nullptr과의 특수화된 비교
            default_func(7);
        else
            void_func_(7);
    }
private:
    SomeVoidFunc void_func_{};
};
void user_func(int i)
{
    std::cout << (i + 1) << '\n';
}
int main()
{
    C c1;
    C c2(user_func);
    c1();
    c2();
}

출력:

7
8

참고 항목

std::move_only_function 이 대상을 가지고 있는지 확인합니다
(public member function)
(removed in C++20)
std::function nullptr 을 비교합니다
(function template)