#include /** Adapt functor to static method where functor passed as context. * Main use case to convert lambda into function that can be passed into JIT code. */ template class FunctorToStaticMethodAdaptor : public FunctorToStaticMethodAdaptor { }; template class FunctorToStaticMethodAdaptor { public: static R call(C * ptr, Args &&... arguments) { return std::invoke(&C::operator(), ptr, std::forward(arguments)...); } static R unsafeCall(char * ptr, Args &&... arguments) { C * ptr_typed = reinterpret_cast(ptr); return std::invoke(&C::operator(), ptr_typed, std::forward(arguments)...); } }; template class FunctorToStaticMethodAdaptor { public: static R call(C * ptr, Args &&... arguments) { return std::invoke(&C::operator(), ptr, std::forward(arguments)...); } static R unsafeCall(char * ptr, Args &&... arguments) { C * ptr_typed = static_cast(ptr); return std::invoke(&C::operator(), ptr_typed, std::forward(arguments)...); } };