Source: classlib/include/classlib/stdtempl.h
|
|
|
|
/***************************************************************************
stdtempl.h - funzioni templates standard di utilita' generale
-------------------
begin : ven dic 7 17:40:01 CET 2001
copyright : (C) 2001 by Nicola De Nisco
email : nicola@winada.it
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/**
Implements commonly used template functions min(), max(), range()
T tmin( T, T ) returns the lesser of its arguments
T tmin( T, T, T ) returns the least of its arguments
T tmax( T, T ) returns the greater of its arguments
T tmax( T, T, T ) returns the greatest of its arguments
T trange( T minVal, T maxVal, T val ) returns val if val is
between minVal and maxVal. If val is greater than maxVal,
returns maxVal. If val is less than minVal, returns minVal.
*/
#if !defined( __CLASSLIB_STDTEMPL_H )
#define __CLASSLIB_STDTEMPL_H
#if !defined( __CLASSLIB_DEFS_H )
#include "classlib/defs.h"
#endif // __CLASSLIB_DEFS_H
#if !defined( __MINMAX_DEFINED ) // avoid conflict with RTL
#define __MINMAX_DEFINED
/**
Template min function. Return the min value from the supplied one.
*/
template inline const T& tmin( const T& t1, const T& t2 )
{
return t1>t2 ? t2 : t1;
}
/**
Template max function. Return the max value from the supplied one.
*/
template inline const T& tmax( const T& t1, const T& t2 )
{
return t1>t2 ? t1 : t2;
}
/**
Template min function. Return the min value from the supplied one.
*/
template inline const T& tmin( const T& t1, const T& t2, const T& t3 )
{
return t1>t2 ? (t2>t3 ? t3 : t2) : (t1>t3 ? t3 : t1 );
}
/**
Template max function. Return the max value from the supplied one.
*/
template inline const T& tmax( const T& t1, const T& t2, const T& t3 )
{
return t1>t2 ? (t1>t3 ? t1 : t3) : (t2>t3 ? t2 : t3);
}
#endif // __MINMAX_DEFINED
/**
Template range function. It ensure return value is inside the suppied limits.
*/
template inline const T& trange( const T& minVal, const T& maxVal, const T& val )
{
return min( maxVal, max( minVal, val ) );
}
#endif // __CLASSLIB_STDTEMPL_H
Generated by: nicola on gulliver.wadahome.it on Sun May 25 13:54:34 2003, using kdoc 2.0a53. |