This is the answer of Exercise #9: No for-loops.
Replace the for-loop. You will need:
#include <vector> void Halve (std::vector<double>& v) { const int sz = static_cast<int>(v.size()); for (int i=0; i!=sz; ++i) { v[i]/=2.0; } }
#include <algorithm> #include <numeric> #include <vector> //From http://www.richelbilderbeek.nl/CppHalve.htm void Halve (std::vector<double>& v) { std::transform(v.begin(),v.end(),v.begin(), std::bind2nd(std::divides<double>(),2.0)); }