operator== (std::move_only_function)
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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
によって発見されます。
!=
演算子は
synthesized
され、
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) |