Standard deviation from iterators I want this to be similar to the STL algorithms but I don't find it elegant nor concise at all:

#include &lt;iostream&gt;
#include &lt;iterator&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using E = double;
template &lt;typename IT&gt;
E std_dev(IT begin, IT end){
    auto N = std::distance(begin, end);
    E average = std::accumulate(begin, end, E()) / N;
    auto sum_term = [average](E init, E value)-&gt; E{ 
        return init + (value - average)*(value - average);
    };
    E variance = std::accumulate(begin,  end, E(), sum_term);
    return std::sqrt(variance * 1.0 / (N - 1));
}


int main(){
    std::vector&lt;double&gt; stuff {3.5, 3.4, 3.6, 3.9, 3.5, 3.5, 3.5, 3.5, 3.5};
    std::cout &lt;&lt; std_dev(stuff.begin(), stuff.end()) &lt;&lt; "\n";
}
Firstly, make it correct.

N is integral, you could make it E so you don't accidentally do integer arithmetic.

N-1 is wrong.

Rename average to mean. 

Don't hardcode E.

You get:

template &lt;typename It, typename E = typename std::iterator_traits&lt;It&gt;::value_type&gt;
E std_dev(It begin, It end){
    E N = std::distance(begin, end);
    E const mean = std::accumulate(begin, end, E()) / N;
    auto sum_term = [mean](E init, E value)-&gt; E { return init + (value - mean)*(value - mean); };
    E variance = std::accumulate(begin, end, E(), sum_term);
    return std::sqrt(variance / N);
}


Slightly stylized, with comparison to Boost Accumulator: 

Live On Coliru

#include &lt;iostream&gt;
#include &lt;iterator&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

#include &lt;boost/accumulators/accumulators.hpp&gt;
#include &lt;boost/accumulators/statistics.hpp&gt;

template &lt;typename It, typename E = typename std::iterator_traits&lt;It&gt;::value_type, typename R = typename std::common_type&lt;double, E&gt;::type&gt;
R std_dev_boost(It begin, It end){
    namespace ba = boost::accumulators;

    ba::accumulator_set&lt;R, ba::stats&lt;ba::tag::variance&gt; &gt; accu;
    std::for_each(begin, end, std::ref(accu));
    return std::sqrt(ba::variance(accu));
}

template &lt;typename It, 
    typename E = typename std::iterator_traits&lt;It&gt;::value_type, 
    typename R = typename std::common_type&lt;double, E&gt;::type&gt;
R std_dev(It b, It e)
{
    R N          = std::distance(b, e);
    R const mean = std::accumulate(b, e, R{}) / N;
    R variance   = std::accumulate(b, e, R{}, [mean](R a, E v)-&gt; R { return a + (v-mean)*(v-mean); });
    return std::sqrt(variance / N);
}

int main(){
    std::vector&lt;int&gt; stuff {35, 34, 36, 39, 35, 35, 35, 35, 35};
    std::cout &lt;&lt; std_dev_boost(stuff.begin(), stuff.end()) &lt;&lt; "\n";
    std::cout &lt;&lt; std_dev      (stuff.begin(), stuff.end()) &lt;&lt; "\n";
}


Prints

1.34256
1.34256