PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/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. // Some template definitions
  3. template<class T> T max(T a, T b) { return a>b ? a : b; }
  4. template<class T> class vector {
  5. T *v;
  6. int sz;
  7. public:
  8. vector(int _sz) {
  9. v = new T[_sz];
  10. sz = _sz;
  11. }
  12. T &get(int index) {
  13. return v[index];
  14. }
  15. void set(int index, T &val) {
  16. v[index] = val;
  17. }
  18. #ifdef SWIG
  19. %extend {
  20. T getitem(int index) {
  21. return $self->get(index);
  22. }
  23. void setitem(int index, T val) {
  24. $self->set(index,val);
  25. }
  26. }
  27. #endif
  28. };