summaryrefslogtreecommitdiff
path: root/Examples/test-suite/template_empty_inherit.i
blob: 5677b8b1a02abc441b6cc25b321a329a4d9ead90 (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
%module template_empty_inherit

%rename(FunctorOperator) operator();

%inline %{
template<class Arg, typename Result> struct Functor {
  virtual Result operator()(Arg x) const = 0;
  virtual ~Functor() {}
};
%}

// Bug fix - %ignore was resulting in this warning:
// Warning 401: Base class 'Functor< int,int >' has no name as it is an empty template instantiated with '%template()'. Ignored.
%ignore Functor<int, int>;
%template() Functor<int, int>;

%inline %{
#include <algorithm>
#include <iterator>
struct SquareFunctor : Functor<int, int> {
  int operator()(int v) const { return v*v; }
};
%}

%include <std_vector.i>
%template(VectorInt) std::vector<int>;

%inline %{
std::vector<int> squares(const std::vector<int>& vi) {
  std::vector<int> result;
  std::transform(vi.begin(), vi.end(), std::back_inserter(result), SquareFunctor());
  return result;
}
%}