PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1.3.35/Examples/pike/template/example.h

#
C++ Header | 32 lines | 26 code | 4 blank | 2 comment | 0 complexity | f6ca43290440c94abb42f86124ec2d21 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 1/* File : example.h */
 2
 3// Some template definitions
 4
 5template<class T> T max(T a, T b) { return  a>b ? a : b; }
 6
 7template<class T> class vector {
 8  T *v;
 9  int sz;
10 public:
11  vector(int _sz) {
12    v = new T[_sz];
13    sz = _sz;
14  }
15  T &get(int index) {
16    return v[index];
17  }
18  void set(int index, T &val) {
19    v[index] = val;
20  }
21#ifdef SWIG
22  %extend {
23    T getitem(int index) {
24      return $self->get(index);
25    }
26    void setitem(int index, T val) {
27      $self->set(index,val);
28    }
29  }
30#endif
31};
32