Click here to Skip to main content
15,891,431 members
Articles / Desktop Programming / MFC

Extend collections

Rate me:
Please Sign up or sign in to vote.
3.27/5 (7 votes)
11 Dec 1999 87.6K   1.6K   24  
Extended Collection classes to provide copy, compare and find operations with 2 dimensional arrays and maps
#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.

License

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


Written By
Technical Lead Doclogix
Lithuania Lithuania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions