summaryrefslogtreecommitdiff
path: root/Examples/test-suite/lib_std_deque.i
blob: c0cfee020ef4a3017699a4e9a5f14d160290ab40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
%module lib_std_deque

%include "std_deque.i"

%{
#include <algorithm>
#include <functional>
#include <numeric>
%}

namespace std {
    %template(IntDeque) deque<int>;
}

%template(DoubleDeque) std::deque<double>;

%inline %{
typedef float Real;
%}

namespace std {
    %template(RealDeque) deque<Real>;
}

%inline %{

double average(std::deque<int> v) {
    return std::accumulate(v.begin(),v.end(),0.0)/v.size();
}

std::deque<float> half(const std::deque<float>& v) {
    std::deque<float> w(v);
    for (unsigned int i=0; i<w.size(); i++)
        w[i] /= 2.0;
    return w;
}

void halve_in_place(std::deque<double>& v) {
    std::transform(v.begin(),v.end(),v.begin(),
                   std::bind2nd(std::divides<double>(),2.0));
}

%}