From c3d9c326155a763314eb75856e57c98d135a8dcc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 Jun 2016 10:35:26 +0200 Subject: [PATCH] util/BindMethod: add nullptr constructor and bool operator --- src/util/BindMethod.hxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util/BindMethod.hxx b/src/util/BindMethod.hxx index f0ff1cf30..968a593f3 100644 --- a/src/util/BindMethod.hxx +++ b/src/util/BindMethod.hxx @@ -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)...); }