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>);
117 typename detail::template get_class_from_member_function_pointer<
119 static_assert(std::is_invocable_v<Deallocator, Container>,
120 "deallocator must have signature void(S::*)()");
122 std::is_same_v<std::invoke_result_t<Deallocator, Container>,
void>,
123 "deallocator must return void");
125 struct CallbackImpl :
public Callback {
126 std::weak_ptr<Container> weak_ref;
127 CallbackImpl(std::shared_ptr<Container>
const &ref) : weak_ref{ref} {}
128 ~CallbackImpl()
override {
129 if (
auto const ref = weak_ref.lock()) {
130 (ref.get()->*deallocator)();
135 static std::unique_ptr<Callback>
136 make_callback(std::shared_ptr<Container>
const &container) {
137 return std::make_unique<CallbackImpl>(container);