#ifndef DELEGATE_H #define DELEGATE_H namespace icinga { template int delegate_fwd(int (TObject::*function)(TArgs), weak_ptr wref, TArgs args) { shared_ptr ref = wref.lock(); if (!ref) return -1; return (ref.get()->*function)(args); } template function bind_weak(int (TObject::*function)(TArgs), const weak_ptr& wref) { return bind(&delegate_fwd, function, wref, _1); } template function bind_weak(int (TObject::*function)(TArgs), shared_ptr ref) { weak_ptr wref = weak_ptr(ref); return bind_weak(function, wref); } template function bind_weak(int (TObject::*function)(TArgs), shared_ptr ref) { weak_ptr wref = weak_ptr(static_pointer_cast(ref)); return bind_weak(function, wref); } } #endif /* DELEGATE_H */