|
#ifndef __SWAP_H__
#define __SWAP_H__
// swaps two elements
template<class T> inline void Swap(T& x, T& y)
{
T temp;
temp = x;
x = y;
y = temp;
}
// swaps two elements and returns value
// usefull for situation when need return old value
template<class T> inline T& SwapRet(T& x, T& y)
{
T temp;
temp = x;
x = y;
y = temp;
return x;
}
// template function returns y if x < y
// To avoid conflicts with min and max in WINDEF.H
template<class T> inline const T& Max(const T& x, const T& y)
{
if(x > y)
{
return x;
}
return y;
}
// template function returns y if x > y
// To avoid conflicts with min and max in WINDEF.H
template<class T> inline const T& Min(const T& x, const T& y)
{
if(x < y)
{
return x;
}
return y;
}
#endif
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.