home *** CD-ROM | disk | FTP | other *** search
/ HOT Scene Stuff / hotscenestuffzyklop1996.iso / demos / sunknown / template.h < prev    next >
C/C++ Source or Header  |  1994-04-05  |  727b  |  58 lines

  1. // VARIOUS TEMPLATES
  2.  
  3. #ifndef _TEMPLATE_H
  4. #define _TEMPLATE_H
  5.  
  6. // ABS
  7.  
  8. template <class type>
  9. inline type abs(type nr)
  10. {
  11.     return (nr>=0)?nr:-nr;
  12. }
  13.  
  14. // SWAP
  15.  
  16. template <class type>
  17. inline void swap(type& nr1,type& nr2)
  18. {
  19.     type temp=nr1;
  20.     nr1=nr2;
  21.     nr2=temp;
  22. }
  23.  
  24. // MAX
  25.  
  26. template <class type>
  27. inline type max(type nr1,type nr2)
  28. {
  29.     return nr1>nr2?nr1:nr2;
  30. }
  31.  
  32. // MIN
  33.  
  34. template <class type>
  35. inline type min(type nr1,type nr2)
  36. {
  37.     return nr1<nr2?nr1:nr2;
  38. }
  39.  
  40. // SORT
  41.  
  42. template <class type>
  43. inline void sort(type& nr1,type& nr2)
  44. {
  45.     if (nr1>nr2)
  46.         swap(nr1,nr2);
  47. }
  48.  
  49. // FIT
  50.  
  51. template <class type>
  52. void fit(type nr1,type& nr2,type nr3)
  53. {
  54.     nr2=max(nr1,nr2);
  55.     nr2=min(nr2,nr3);
  56. }
  57.  
  58. #endif