source: git/factory/templates/ftmpl_functions.h @ 7194edf

spielwiese
Last change on this file since 7194edf was b1dfaf, checked in by Frank Seelisch <seelisch@…>, 14 years ago
patch from Kai (checked for problems under Windows OS: no problems) git-svn-id: file:///usr/local/Singular/svn/trunk@13210 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.9 KB
Line 
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//}}}
41template <class T>
42inline 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//}}}
58template <class T>
59inline 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//}}}
78template <class T>
79inline T tabs ( const T & a )
80{
81    return (a > T( 0 )) ? a : -a;
82}
83//}}}
84
85#endif /* ! INCL_FUNCTIONS_H */
Note: See TracBrowser for help on using the repository browser.