/tags/rel-1-3-26/SWIG/Examples/guile/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 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