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 или qualified lookup , и может быть найдена только с помощью argument-dependent lookup , когда std::move_only_function<FunctionType> является ассоциированным классом аргументов.

Оператор != синтезируется из 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)