lundi 25 janvier 2016

Wrap std::function in another std::function?

I'd like to wrap the result of a std::bind() or a lambda in a helper function that tracks the execution time of calls to the function. I'd like a generalized solution that will work with any number of parameters (and class methods).

My intent is to take the wrapped function and pass it to a boost::signals2::signal so the resulting function object needs to be identical in signature to the original function.

I'm basically looking for some magical class or function Wrapper that works like this:

std::function<void(int)> f = [](int x) {
    std::cerr << x << std::endl;
};

boost::signals2::signal<void(int)> x_signal;
x_signal.connect(Wrapper<void(int)>(f));
x_signal(42);

that would time how long it took to print 42.

Thanks!

Aucun commentaire:

Enregistrer un commentaire