operator==(std::move_only_function)
cppreference.net에서 가져옴
friend bool operator==( const std::move_only_function& f, std::nullptr_t ) noexcept;
|
(C++23부터) | |
래퍼 f에 호출 가능한 대상이 있는지 여부를 std::nullptr_t와 공식적으로 비교하여 확인합니다. 빈 래퍼(즉, 대상이 없는 래퍼)는 같음으로 비교되고, 비어 있지 않은 함수는 같지 않음으로 비교됩니다.
이 함수는 일반적인 비한정 또는 한정 조회에 표시되지 않으며, 인자 종속 조회를 통해서만 찾을 수 있습니다. 이때 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) |