108 template <
class C>
struct get_class_from_member_function_pointer;
109 template <
class C,
class Ret,
class... Args>
110 struct get_class_from_member_function_pointer<Ret (C::*)(Args...)> {
114 using Deallocator =
decltype(deallocator);
115 static_assert(std::is_member_function_pointer_v<Deallocator>);
116 using Container = detail::template get_class_from_member_function_pointer<
118 static_assert(std::is_invocable_v<Deallocator, Container>,
119 "deallocator must have signature void(S::*)()");
121 std::is_same_v<std::invoke_result_t<Deallocator, Container>,
void>,
122 "deallocator must return void");
124 struct CallbackImpl :
public Callback {
125 std::weak_ptr<Container> weak_ref;
126 CallbackImpl(std::shared_ptr<Container>
const &ref) : weak_ref{ref} {}
127 ~CallbackImpl()
override {
128 if (
auto const ref = weak_ref.lock()) {
129 (ref.get()->*deallocator)();
134 static std::unique_ptr<Callback>
135 make_callback(std::shared_ptr<Container>
const &container) {
136 return std::make_unique<CallbackImpl>(container);