template example working, sorry forgot to commit it earlier

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4531 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2003-03-12 22:48:02 +00:00
commit ae1a166c19
5 changed files with 120 additions and 0 deletions

View file

@ -0,0 +1,32 @@
/* File : example.h */
// Some template definitions
template<class T> T max(T a, T b) { return a>b ? a : b; }
template<class T> class vector {
T *v;
int sz;
public:
vector(int _sz) {
v = new T[_sz];
sz = _sz;
}
T &get(int index) {
return v[index];
}
void set(int index, T &val) {
v[index] = val;
}
#ifdef SWIG
%extend {
T getitem(int index) {
return self->get(index);
}
void setitem(int index, T val) {
self->set(index,val);
}
}
#endif
};