jeudi 25 mai 2017

How should we use template with std::accumulate in a function to return right type by cosidering template not "init"

The type of return from std::accumulate depends on the "init" i.e. if it is integer it will return integer and if it is double it will return double.

I have a template function for sum like this:

T mean(std::vector<T> vector)
{
    T sum = std::accumulate(vector.begin(), vector.end(), X);
}

What should I put instead of X?

Aucun commentaire:

Enregistrer un commentaire