1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id$ */ |
---|
3 | |
---|
4 | #ifndef INCL_FUNCTIONS_H |
---|
5 | #define INCL_FUNCTIONS_H |
---|
6 | |
---|
7 | //{{{ docu |
---|
8 | // |
---|
9 | // ftmpl_functions.h - 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 | // #include <factory/factoryconf.h> |
---|
30 | |
---|
31 | //{{{ template <class T> inline T tmax ( const T & a, const T & b ) |
---|
32 | //{{{ docu |
---|
33 | // |
---|
34 | // tmax() - return the maximum of `a' and `b'. |
---|
35 | // |
---|
36 | // Developers note: |
---|
37 | // ---------------- |
---|
38 | // `T' should have an `operator >()'. |
---|
39 | // |
---|
40 | //}}} |
---|
41 | template <class T> |
---|
42 | inline T tmax ( const T & a, const T & b ) |
---|
43 | { |
---|
44 | return (a > b) ? a : b; |
---|
45 | } |
---|
46 | //}}} |
---|
47 | |
---|
48 | //{{{ template <class T> inline T tmin ( const T & a, const T & b ) |
---|
49 | //{{{ docu |
---|
50 | // |
---|
51 | // tmin() - return the minimum of `a' and `b'. |
---|
52 | // |
---|
53 | // Developers note: |
---|
54 | // ---------------- |
---|
55 | // `T' should have an `operator <()'. |
---|
56 | // |
---|
57 | //}}} |
---|
58 | template <class T> |
---|
59 | inline T tmin ( const T & a, const T & b ) |
---|
60 | { |
---|
61 | return (a < b) ? a : b; |
---|
62 | } |
---|
63 | //}}} |
---|
64 | |
---|
65 | //{{{ template <class T> inline T tabs ( const T & a ) |
---|
66 | //{{{ docu |
---|
67 | // |
---|
68 | // tabs() - return the absolute value of `a'. |
---|
69 | // |
---|
70 | // `a' is negated iff it is less or equal `T( 0 )'. |
---|
71 | // |
---|
72 | // Developers note: |
---|
73 | // ---------------- |
---|
74 | // `T' should have an `operator >()', an `operator -()', and a |
---|
75 | // `T::T( int )' constructor. |
---|
76 | // |
---|
77 | //}}} |
---|
78 | template <class T> |
---|
79 | inline T tabs ( const T & a ) |
---|
80 | { |
---|
81 | return (a > T( 0 )) ? a : -a; |
---|
82 | } |
---|
83 | //}}} |
---|
84 | |
---|
85 | #endif /* ! INCL_FUNCTIONS_H */ |
---|