I guess what you want is a pointer to your deprecated signature.
Here is the C ++ 11 approach.
template<class Sig, class F> struct magic_callback_t; template<class R, class...Args, class F> struct magic_callback_t<R(Args...), F> { F f; void* pvoid() const { return this; } using result_sig = R(*)(void*, Args...); result_sig pfunc() const { return [](void* pvoid, Args...args)->R{ auto* self = static_cast<magic_callback_t*>(pvoid); return (self->f)(std::forward<Args>(args)...); }; } }; template<class Sig, class F> magic_callback_t<Sig, F> magic_callback( F&& f ) { return {std::forward<F>(f)}; }
Now we just do this:
auto callback = magic_callback( [&](){ // use whatever as if we where in the enclosing scope }); void(*)(void*) legacy_ptr = callback.pfunc(); legacy_ptr( callback.pvoid() );
will call the lambda you passed in to magic_callback .
If you want to store material as a tuple, you can. Just take a tuple in lambda, then use std::get to access it in the body of the lambda. Use mutable if you want it to change.
source share