jeudi 23 avril 2015

pass a function template as an argument

Could some one help me how to implement this code?

I need to pass a function to another function:

std::cout << process_time(Model::method1) << std::endl;

This function gets the function as a template type and calls it on an object

template <typename F>
double process_time(F algorithm)
{
    Model model;
    double time=0;
    do
    {
        // ...
        time += model.algorithm(arg1);
    } while (! stop_criteria);
    return time;
}

Note that method1 is a function template as well:

template <typename T>
double method1(std::vector<T> &v)
{
    ...
}

What is the legal syntax for it?

Aucun commentaire:

Enregistrer un commentaire