source: git/factory/templates/ftmpl_functions.h @ fb1675

spielwiese
Last change on this file since fb1675 was fb1675, checked in by Hans Schoenemann <hannes@…>, 7 years ago
use include ".." for singular related .h, p8
  • Property mode set to 100644
File size: 1.8 KB
Line 
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**/
38template <class T>
39inline 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**/
53template <class T>
54inline 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**/
71template <class T>
72inline T tabs ( const T & a )
73{
74    return (a > T( 0 )) ? a : -a;
75}
76
77#endif /* ! INCL_FUNCTIONS_H */
Note: See TracBrowser for help on using the repository browser.