I am using vector containers to store an array of drums. Without using a loop, there is a quick way to multiply each element in my vector by a few scalers
For example:
vector & lt; Double & gt; Array (10,1); will start an array of 10 pairs with the initial value 1. To multiply this array by 0.5, I will write:
for (unsigned) Int i = 0; I & lt; Array.size (); i ++) array [i] = 0.5 * array [i]; Is there any other way? I used the Valarere which overloads the operator '*' so that:
array = 0.5 * array; Valid, but I did not want to use Veraarera because it seems that vector container is a more standard approach to tampering with ARA.
Thank you!
You can:
std :: transform ( Array .begin (), array.and (), array.bizin (), std :: bind2nd (std :: multiplies & lt; double & gt; (), 0.5)); In answer to the sum of the elements:
double sum = std :: cached (Array.begin (), Array.end (), 0.0); and in response to receiving each code for sqrt :
std :: transform (Array.begin ()) , Array.end (), Array.bigin (), Static_cast & lt; Double (*) (double)> (Std :: sqrt)); This cast is to select the correct overload.
Comments
Post a Comment