mardi 29 septembre 2015

C++11 std::multiplies on vector containing 0's

I have a vector, containing the following values

0 0 1 1

And my aim is to multiply this vector and return a double, for this, I am using the std::accumulate and std::multiplies but I have noticed a problem, because there is 0's contained the returning value is always 0. For example (0 * 0 * 1 * 1) = 0

Is it possible to do use std::multiplies to ignore all values that are 0's? Technically, in this part, I am just after the result of: (1 * 1) for example.

I am using:

std::accumulate(diag1.begin(), diag1.end(), 1, std::multiplies<double>());

Where diag1 contains the values inside this example.

Aucun commentaire:

Enregistrer un commentaire