I have written the following function in order to normalize a container of double, so that it sums up to 1.0:/** * @brief This function normalizes a container so that it sums to 1.0. * * @param begin The beginning of the range to normalize. * @param end The end of the range to normalize. * @param out The beginning of the output range (can be the same as begin). */template <typename InputIterator, typename OutputIterator>void normalizeProbability(InputIterator begin, InputIterator end, OutputIterator out) {    double norm = static_cast<double>(std::accumulate(begin, end, 0.0));    std::transform(begin, end, out, [norm](decltype(*begin) t){ return t/norm; });}Is it possible to do better, or having a more precise result?
Function that normalizes a vector of double
c++;optimization;floating point