~ubuntu-branches/ubuntu/hoary/swig1.3/hoary

« back to all changes in this revision

Viewing changes to Examples/guile/std_vector/example.h

  • Committer: Bazaar Package Importer
  • Author(s): Thom May
  • Date: 2004-08-02 15:57:10 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040802155710-bm292q1d6x6tw7gc
Tags: 1.3.21-5ubuntu1
Fix linking for ruby, python, perl and tcl bindings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* File : example.h */
 
2
 
 
3
#include <vector>
 
4
#include <algorithm>
 
5
#include <functional>
 
6
#include <numeric>
 
7
 
 
8
double average(std::vector<int> v) {
 
9
    return std::accumulate(v.begin(),v.end(),0.0)/v.size();
 
10
}
 
11
 
 
12
std::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
 
 
19
void 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