113 template <
class C>
struct get_class_from_method;
114 template <
class C,
class Ret,
class... Args>
115 struct get_class_from_method<Ret (C::*)(Args...)> {
116#if defined(__NVCC__) or defined(__NVCOMPILER) or \
117 defined(__GNUC__) and __GNUC__ < 13
121 "deallocator must have signature void(S::*)() noexcept");
124 template <
class C,
class Ret,
class... Args>
125 struct get_class_from_method<Ret (C::*)(Args...) noexcept> {
129 using Deallocator =
decltype(deallocator);
130 static_assert(std::is_member_function_pointer_v<Deallocator>);
131 using Container = detail::template get_class_from_method<Deallocator>::type;
132 static_assert(std::is_invocable_v<Deallocator, Container>,
133 "deallocator must have signature void(S::*)() noexcept");
135 std::is_same_v<std::invoke_result_t<Deallocator, Container>,
void>,
136 "deallocator must return void");
138 struct CallbackImpl :
public Callback {
139 std::weak_ptr<Container> weak_ref;
140 CallbackImpl(std::shared_ptr<Container>
const &ref) : weak_ref{ref} {}
141 ~CallbackImpl()
override {
142 if (
auto const ref = weak_ref.lock()) {
143 (ref.get()->*deallocator)();
148 static std::unique_ptr<Callback>
149 make_callback(std::shared_ptr<Container>
const &container) {
150 return std::make_unique<CallbackImpl>(container);