second std2 template which additionally takes the mean value of the data

In the I-SO process the mean is calculated by itself just before the std2 function is called. It is a little wasteful to do the exact same thing again within the std2().
I have therefore created a second std2() template which additionally takes the previously created double mean.

Hope this makes sense to you ::