1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|

2 | |
---|

3 | #ifndef INCL_FUNCTIONS_H |
---|

4 | #define INCL_FUNCTIONS_H |
---|

5 | |
---|

6 | /** |
---|

7 | * |
---|

8 | * @file ftmpl_functions.h |
---|

9 | * some useful template functions. |
---|

10 | * |
---|

11 | * Header file corresponds to: nothing |
---|

12 | * |
---|

13 | * Hierarchy: bottom, templates |
---|

14 | * |
---|

15 | * Developer note: |
---|

16 | * --------------- |
---|

17 | * Sooner or later you need them: functions to calculate the |
---|

18 | * minimum or maximum of two values or the absolute value. Here |
---|

19 | * they are. All of them are inlined, hence there is no source |
---|

20 | * file corresponding to `ftmpl_functions.h'. |
---|

21 | * |
---|

22 | * The functions are for internal use only (i.e., to build the |
---|

23 | * library), hence they should not be included from `factory.h'. |
---|

24 | * However, we have to install `ftmpl_functions.h' with the other |
---|

25 | * templates since the functions have to be instantiated. |
---|

26 | * |
---|

27 | **/ |
---|

28 | |
---|

29 | /** template <class T> inline T tmax ( const T & a, const T & b ) |
---|

30 | * |
---|

31 | * tmax() - return the maximum of `a' and `b'. |
---|

32 | * |
---|

33 | * Developers note: |
---|

34 | * ---------------- |
---|

35 | * `T' should have an `operator >()'. |
---|

36 | * |
---|

37 | **/ |
---|

38 | template <class T> |
---|

39 | inline T tmax ( const T & a, const T & b ) |
---|

40 | { |
---|

41 | return (a > b) ? a : b; |
---|

42 | } |
---|

43 | |
---|

44 | /** template <class T> inline T tmin ( const T & a, const T & b ) |
---|

45 | * |
---|

46 | * tmin() - return the minimum of `a' and `b'. |
---|

47 | * |
---|

48 | * Developers note: |
---|

49 | * ---------------- |
---|

50 | * `T' should have an `operator <()'. |
---|

51 | * |
---|

52 | **/ |
---|

53 | template <class T> |
---|

54 | inline T tmin ( const T & a, const T & b ) |
---|

55 | { |
---|

56 | return (a < b) ? a : b; |
---|

57 | } |
---|

58 | |
---|

59 | /** template <class T> inline T tabs ( const T & a ) |
---|

60 | * |
---|

61 | * tabs() - return the absolute value of `a'. |
---|

62 | * |
---|

63 | * `a' is negated iff it is less or equal `T( 0 )'. |
---|

64 | * |
---|

65 | * Developers note: |
---|

66 | * ---------------- |
---|

67 | * `T' should have an `operator >()', an `operator -()', and a |
---|

68 | * `T::T( int )' constructor. |
---|

69 | * |
---|

70 | **/ |
---|

71 | template <class T> |
---|

72 | inline T tabs ( const T & a ) |
---|

73 | { |
---|

74 | return (a > T( 0 )) ? a : -a; |
---|

75 | } |
---|

76 | |
---|

77 | #endif /* ! INCL_FUNCTIONS_H */ |
---|