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 ;
(desde C++23)

Comprueba si el wrapper f tiene un destino invocable comparándolo formalmente con std::nullptr_t . Los wrappers vacíos (es decir, wrappers sin destino) comparan iguales, los wrappers no vacíos comparan no iguales.

Esta función no es visible para la búsqueda unqualified o qualified ordinaria, y solo puede ser encontrada mediante argument-dependent lookup cuando std::move_only_function<FunctionType> es una clase asociada de los argumentos.

El operador != es sintetizado a partir de operator== .

Contenidos

Parámetros

f - std::move_only_function para comparar

Valor de retorno

! f .

Ejemplo

#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) // comparación especializada con 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();
}

Salida:

7
8

Véase también

verifica si el std::move_only_function tiene un objetivo
(función miembro pública)
(eliminado en C++20)
compara un std::function con nullptr
(plantilla de función)