6
// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514
7
template<class T> class Sum {
10
Sum(T i = 0) : res(i) { }
11
void operator() (T x) { res += x; }
12
T result() const { return res; }
17
// Rename the application operator to __call__ for python.
18
// Note: this is normally automatic, but if you had to do it yourself
19
// you would use this directive:
21
// %rename(__call__) *::operator();
23
// Instantiate a few versions
24
%template(intSum) Sum<int>;
25
%template(doubleSum) Sum<double>;