7#if !defined(ASYNC_MQTT_UTIL_SCOPE_GUARD_HPP)
8#define ASYNC_MQTT_UTIL_SCOPE_GUARD_HPP
16template <
typename Proc>
20 :proc_{std::move(proc)}
22 unique_sg(unique_sg
const&) =
delete;
23 unique_sg(unique_sg&& other)
28 if (!moved_) std::move(proc_)();
38template <
typename Proc>
39inline detail::unique_sg<Proc> unique_scope_guard(Proc&& proc) {
40 return detail::unique_sg<Proc>{std::forward<Proc>(proc)};
43template <
typename Proc>
44inline auto shared_scope_guard(Proc&& proc) {
45 auto deleter = [proc = std::forward<Proc>(proc)](
void*)
mutable { std::move(proc)(); };
46 return std::shared_ptr<void>(
nullptr, std::move(deleter));