PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1.3.35/Examples/ruby/std_vector/example.h

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