/* * Copyright (C) 2014 Cloudius Systems, Ltd. */ #ifndef UTIL_DEFER_HH_ #define UTIL_DEFER_HH_ template class deferred_action { Func _func; bool _cancelled = false; public: deferred_action(Func&& func) : _func(std::move(func)) {} ~deferred_action() { _func(); } void cancel() { _cancelled = true; } }; template inline deferred_action defer(Func&& func) { return deferred_action(std::forward(func)); } #endif /* UTIL_DEFER_HH_ */