util/BindMethod: add nullptr constructor and bool operator

This commit is contained in:
Max Kellermann 2016-06-20 10:35:26 +02:00
parent a938b609b9
commit c3d9c32615
1 changed files with 13 additions and 0 deletions

View File

@ -60,6 +60,19 @@ public:
BoundMethod(void *_instance, function_pointer _function)
:instance_(_instance), function(_function) {}
/**
* Construct an "undefined" object. It must not be called,
* and its "bool" operator returns false.
*/
BoundMethod(std::nullptr_t):function(nullptr) {}
/**
* Was this object initialized with a valid function pointer?
*/
operator bool() const {
return function != nullptr;
}
R operator()(Args... args) const {
return function(instance_, std::forward<Args>(args)...);
}