Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C++

C++ Standard Allocator, An Introduction and Implementation

Rate me:
Please Sign up or sign in to vote.
4.91/5 (26 votes)
18 Aug 2003CPOL10 min read 293.8K   1.8K   102  
Introduction to the allocator concept, as well as implementing a policy-driven allocator template class
// Generated by Henrik Stuart's .hpp generator: www.unprompted.com/hstuart/
#ifndef typetraits_hpp_ad8a45ea_f617_444c_85ed_dfe49806caa9
#define typetraits_hpp_ad8a45ea_f617_444c_85ed_dfe49806caa9


#include <cstdlib>

namespace Dot {

	namespace Traits {

///////////////////////////////////////////////////////////////////////////
//	class streambuf
///////////////////////////////////////////////////////////////////////////

		//	Converts each integral constant into a unique type
		//	Useful for compile time if-else statements
		template<int v>
		struct Int2Type {
			enum { value = v };
		};	//	end of struct Int2Type

///////////////////////////////////////////////////////////////////////////
//	class TypeTraits
///////////////////////////////////////////////////////////////////////////

		//	defines useful typetraits for types
		template<typename T>
		class TypeTraits {
		public : 
			typedef T Type;
			typedef T& RefType;
			typedef T* PointerType;

		protected : 
			inline explicit TypeTraits() {}
			inline ~TypeTraits() {}

		private : 
			inline explicit TypeTraits(TypeTraits const&) {}
			inline TypeTraits& operator=(TypeTraits const&) { return *this; }
		};	//	end of class TypeTraits

///////////////////////////////////////////////////////////////////////////
//	helpers for << operators
///////////////////////////////////////////////////////////////////////////

		//	since unable to overload << due to ambigous calls,
		//	resort to create type traits, and overloading those with problems
		template <typename T>
		struct StreamTypeTraits {
			typedef T StreamT;
		};

		template <>
		struct StreamTypeTraits<std::size_t> {
			typedef unsigned long StreamT;
		};

		template <>
		struct StreamTypeTraits<unsigned char> {
			typedef unsigned short StreamT;
		};

	};	//	end of namespace Traits

};	//	end of namespace Dot


#endif // typetraits_hpp_ad8a45ea_f617_444c_85ed_dfe49806caa9

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Singapore Singapore
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions