#include <utility>
+#include "common/backport14.h"
+
template <typename F>
struct scope_guard {
F f;
scope_guard(scope_guard &&) = default;
scope_guard & operator=(const scope_guard &) = delete;
scope_guard & operator=(scope_guard &&) = default;
+ scope_guard(const F& f) : f(f) {}
scope_guard(F &&f) : f(std::move(f)) {}
+ template<typename... Args>
+ scope_guard(ceph::in_place_t, Args&& ...args) : f(std::forward<Args>(args)...) {}
~scope_guard() {
- f();
+ std::move(f)(); // Support at-most-once functions
}
};
return scope_guard<F>(std::forward<F>(f));
}
+template<typename F, typename... Args>
+scope_guard<F> make_scope_guard(ceph::in_place_type_t<F>, Args&& ...args) {
+ return { ceph::in_place, std::forward<Args>(args)... };
+}
+
#endif