source: git/factory/templates/ftmpl_functions.h @ 362fc67

jengelh-datetimespielwiese
Last change on this file since 362fc67 was 362fc67, checked in by Martin Lee <martinlee84@…>, 11 years ago
chg: remove $Id$
  • Property mode set to 100644
File size: 1.9 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3#ifndef INCL_FUNCTIONS_H
4#define INCL_FUNCTIONS_H
5
6//{{{ docu
7//
8// ftmpl_functions.h - some useful template functions.
9//
10// Header file corresponds to: nothing
11//
12// Hierarchy: bottom, templates
13//
14// Developer note:
15// ---------------
16// Sooner or later you need them: functions to calculate the
17// minimum or maximum of two values or the absolute value.  Here
18// they are.  All of them are inlined, hence there is no source
19// file corresponding to `ftmpl_functions.h'.
20//
21// The functions are for internal use only (i.e., to build the
22// library), hence they should not be included from `factory.h'.
23// However, we have to install `ftmpl_functions.h' with the other
24// templates since the functions have to be instantiated.
25//
26//}}}
27
28// #include <factory/factoryconf.h>
29
30//{{{ template <class T> inline T tmax ( const T & a, const T & b )
31//{{{ docu
32//
33// tmax() - return the maximum of `a' and `b'.
34//
35// Developers note:
36// ----------------
37// `T' should have an `operator >()'.
38//
39//}}}
40template <class T>
41inline T tmax ( const T & a, const T & b )
42{
43    return (a > b) ? a : b;
44}
45//}}}
46
47//{{{ template <class T> inline T tmin ( const T & a, const T & b )
48//{{{ docu
49//
50// tmin() - return the minimum of `a' and `b'.
51//
52// Developers note:
53// ----------------
54// `T' should have an `operator <()'.
55//
56//}}}
57template <class T>
58inline T tmin ( const T & a, const T & b )
59{
60    return (a < b) ? a : b;
61}
62//}}}
63
64//{{{ template <class T> inline T tabs ( const T & a )
65//{{{ docu
66//
67// tabs() - return the absolute value of `a'.
68//
69// `a' is negated iff it is less or equal `T( 0 )'.
70//
71// Developers note:
72// ----------------
73// `T' should have an `operator >()', an `operator -()', and a
74// `T::T( int )' constructor.
75//
76//}}}
77template <class T>
78inline T tabs ( const T & a )
79{
80    return (a > T( 0 )) ? a : -a;
81}
82//}}}
83
84#endif /* ! INCL_FUNCTIONS_H */
Note: See TracBrowser for help on using the repository browser.