sylveon / member_thunk

Dynamically creates executable code to allow C callbacks to call C++ member functions without the need for a user data parameter
MIT License
13 stars 2 forks source link

Sentinel class to allow template argumentless make call #11

Closed sylveon closed 4 years ago

sylveon commented 4 years ago

Can we make member_thunk::make(this, &Foo::bar) valid and deduce the return type?

sylveon commented 4 years ago

Not possible

sylveon commented 4 years ago

Goes in the lines of

template<typename T, typename U>
class sentinel
{
    T *pthis;
    U pfunc;

public:
    template<typename V>
        requires is_compatible_function_types_v<V, T, U>
    operator unique_ptr<thunk<V>>()
    {
        return make<V>(pthis, pfunc);
    }
};

template<typename T, typename U>
sentinel<T, U> make(T *pthis, U pfunc)
{
    return { pthis, pfunc };
}