PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/python/std_vector/example.h

#
C++ Header | 25 lines | 17 code | 6 blank | 2 comment | 1 complexity | 0e9b191f8ca45acbc84c25cc4babcac6 MD5 | raw file
 1/* File : example.h */
 2
 3#include <vector>
 4#include <algorithm>
 5#include <functional>
 6#include <numeric>
 7
 8double average(std::vector<int> v) {
 9    return std::accumulate(v.begin(),v.end(),0.0)/v.size();
10}
11
12std::vector<double> half(const std::vector<double>& v) {
13    std::vector<double> w(v);
14    for (unsigned int i=0; i<w.size(); i++)
15        w[i] /= 2.0;
16    return w;
17}
18
19void halve_in_place(std::vector<double>& v) {
20    // would you believe this is the same as the above?
21    std::transform(v.begin(),v.end(),v.begin(),
22                   std::bind2nd(std::divides<double>(),2.0));
23}
24
25