#include <unistd.h>
#include <thread>
#include <chrono>
#include <mutex>
#include <functional>
#include <iostream>
#include <cmath>

template <typename Res, typename... Args>
struct function_ptr_helper
{
public:
    template<typename function_type>
    static auto bind(function_type&& f) { func = std::forward<function_type>(f); }

	static auto invoke(Args... args) { return func(args...); }
	static auto* ptr() { return &invoke; }

private:
	static std::function<Res(Args ...)> func;
};

template <typename Res, typename... Args>
std::function<Res(Args ...)> function_ptr_helper<Res, Args...>::func;

template <typename Res, typename ... Args>
auto* get_fn_ptr(std::function<Res(Args...)> const& f)
{
	using type = function_ptr_helper<Res, Args...>;
	
	type::bind(f);
	return type::ptr();
}
 
struct test
{
	double operator()(double, double) const
	{
		return 1.0 + c;
	}
	double c=1.0;
};


int main()
{
	std::function<double(double,double)> f = test{};
	
	typedef double (*funcPtr)(double,double);
	
	funcPtr fp = get_fn_ptr(f);
    return 0;
}