#pragma once #include #include #include "object.hpp" template class function_wrapper : public object { public: using user_data_pointer = void*; using c_function_type = ReturnType(Args..., user_data_pointer); using functor_type = std::function; function_wrapper() = default; function_wrapper(functor_type functor) : functor_(std::make_unique(std::move(functor))) { } c_function_type* get_c_function() const { return +[](Args... args, user_data_pointer user_data) -> ReturnType { return (*static_cast(user_data))(std::forward(args)...); }; } void* get_function() const { return reinterpret_cast(this->get_c_function()); } user_data_pointer get_user_data() const { return this->functor_.get(); } private: std::unique_ptr functor_{}; };