- functional[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp11[meta cpp]
namespace std {
// operator==により、以下のオーバーロードが使用可能になる (C++20)
template <class R, class... ArgTypes>
bool operator!=(const function<R(ArgTypes...)>& f, nullptr_t) noexcept; // (1) C++11
template <class R, class... ArgTypes>
bool operator!=(nullptr_t, const function<R(ArgTypes...)>& f) noexcept; // (2) C++11
}
- nullptr_t[link /reference/cstddef/nullptr_t.md]
非等値比較する。
static_cast<bool>(f)
#include <iostream>
#include <functional>
int ident(int x) { return x; }
int main()
{
std::function<int(int)> f = ident;
if (f != nullptr) {
std::cout << "not empty" << std::endl;
}
f = nullptr;
if (f != nullptr) {}
else {
std::cout << "empty" << std::endl;
}
}
not empty
empty
- C++11
- Clang: 3.0 [mark verified]
- GCC: 4.6.4 [mark verified]
- Visual C++: ??
- P1614R2 The Mothership has Landed
- C++20での三方比較演算子の追加と、関連する演算子の自動導出