What I could't find in STL
...so I gotta do it myself...
template<class FIt>
double standard_deviation(FIt first, FIt last)
{
double powersum(0), sum(0);
for(int n = 0 ; first != last ; ++n , ++first)
{
powersum += *first * *first;
sum += *first;
}
if(n <=1)
throw std::range_error("standard_deviation. no data");
return sqrt((n * powersum - sum *sum) / (n *(n -1)));
}
template<class FIt>class not_of_t
{
FIt first_, last_;
public:
not_of_t(FIt first, FIt last) : first_(first), last_(last) { }
template<class T> bool operator()(const T& value) const { return std::find(first_, last_, value) == last_; }
};
template<class FIt>class any_of_t
{
FIt first_, last_;
public:
any_of_t(FIt first, FIt last) : first_(first), last_(last) { }
template<class T> bool operator()(const T& value) const { return std::find(first_, last_, value) != last_; }
};
template<class FIt>inline not_of_t<FIt> not_of(FIt first, FIt last) { return not_of_t<FIt>(first, last); }
template<class FIt>inline any_of_t<FIt> any_of(FIt first, FIt last) { return any_of_t<FIt>(first, last); }
template<class IIt, class FIt>IIt find_first_not_of(IIt first1, IIt last1, FIt first2, FIt last2)
{return std::find_if(first1, last1, not_of(first2, last2));}
template<class IIt, class FIt>IIt find_first_any_of(IIt first1, IIt last1, FIt first2, FIt last2)
{return std::find_if(first1, last1, not_of(first2, last2));}
template<class IIt, class FIt>size_t count_any_of(IIt first1, IIt last1, FIt first2, FIt last2)
{return std::count_if(first1, last1, any_of(first2, last2));}
template<class IIt, class FIt>size_t count_not_of(IIt first1, IIt last1, FIt first2, FIt last2)
{return std::count_if(first1, last1, not_of(first2, last2));}
template<class IIt, class FIt>IIt remove_if_not_of(IIt first1, IIt last1, FIt first2, FIt last2)
{return std::remove_if(first1, last1, not_of(first2, last2));}
template<class IIt, class FIt>IIt remove_if_any_of(IIt first1, IIt last1, FIt first2, FIt last2)
{return std::remove_if(first1, last1, any_of(first2, last2));}
template<class C, class FIt>C& erase_all_not_of(C& c, FIt first, FIt last)
{
for(C::iterator r = c.begin() ; r != c.end() && (r = find_first_not_of(r, c.end(), first, last)) != c.end() ; )
r = c.erase(r);
return c;
}
template<class C, class FIt>C& erase_all_of(C& c, FIt first, FIt last)
{
for(C::iterator r = c.begin() ; r != c.end() && (r = find_first_any_of(r, c.end(), first, last)) != c.end() ; )
r = c.erase(r);
return c;
}
template<class Ii, class Oi>inline void make_upper_case(Ii b, Ii e, Oi ob) { std::transform(b, e, ob, ::toupper); }
template<class Ii, class Oi>inline void make_lower_case(Ii b, Ii e, Oi ob) { std::transform(b, e, ob, ::tolower); }
template<class S>inline S make_upper_case(const S& s) { S x(s); std::transform(s.begin(), s.end(), x.begin(), ::toupper); return x; }
template<class S>inline S make_lower_case(const S& s) { S x(s); std::transform(s.begin(), s.end(), x.begin(), ::tolower); return x; }
template<class S>S replace(S s, const S& fs, const S& rs =S(), size_t ntimes=-1)
{
for(size_t i=0 , p=0 ; i <ntimes && (p = s.find(fs, p)) !=s.npos; ++i , p +=rs.size())
s.replace(p, fs.size(), rs);
return s;
}
template<class S, class CH>inline S trim_of(const S& s, const CH& chrs)
{ size_t nr =s.find_first_not_of(chrs) , nl=s.find_last_not_of(chrs); return nr==s.npos && nl==s.npos? S() : s.substr(nr, nl-nr+1); }
template<class S, class CH>inline S trim_left_of(const S& s, const CH& chrs)
{ size_t n =s.find_first_not_of(chrs); return n != s.npos? s.substr(n) : s.find_last_of(chrs) !=s.npos ? S() : s; }
template<class S, class CH>inline S trim_right_of(const S& s, const CH& chrs)
{ size_t n =s.find_last_not_of(chrs); return n != s.npos? s.substr(0, n+1) : s.find_first_of(chrs) ==0? S() : s; }
template<class S, class CH>inline S trim_not_of(const S& s, const CH& chrs)
{ size_t nr =s.find_first_of(chrs), nl =s.find_last_of(chrs); return nr == s.npos && nl ==s.npos? S() : s.substr(nr, nl-nr+1); }
template<class S, class CH>inline S trim_left_not_of(const S& s, const CH& chrs)
{ size_t n =s.find_first_of(chrs); return n != s.npos? s.substr(n) : s.find_last_not_of(chrs) !=s.npos ? S() : s; }
template<class S, class CH>inline S trim_right_not_of(const S& s, const CH& chrs)
{ size_t n =s.find_last_of(chrs); return n != s.npos? s.substr(0, n+1) : s.find_first_not_of(chrs)==0? S() : s;}
template<class S, class CH>inline size_t count_not_of(const S& s, const CH& chrs)
{ return count_not_of(s.begin(), s.end(), chrs, chrs+S::traits_type::length(chrs)); }
template<class S, class CH>inline size_t count_of(const S& s, const CH& chrs)
{ return count_of(s.begin(), s.end(), chrs, chrs+S::traits_type::length(chrs)); }
template<class S, class CH>inline S strip(const S& s, size_t len, const CH& add)
{ return s.length() >len? s.substr(0, len) +(add? add:L"") : s; }
template<class S, class CH>inline S tail_string(const S& s, size_t len, const CH& add)
{ return s.length() >len? (add? add:L"") +s.substr(s.length() -len): s; }
About me click here (http://home.comcast.net/~GeorgeSalnikov).