Click here to Skip to main content
12,551,853 members (59,424 online)
Click here to Skip to main content
Articles » Languages » C / C++ Language » STL » Downloads


97 bookmarked

C++ Standard Allocator, An Introduction and Implementation

, 18 Aug 2003
Introduction to the allocator concept, as well as implementing a policy-driven allocator template class
// Generated by Henrik Stuart's .hpp generator:
#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.


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


About the Author

Lai Shiaw San Kent
Web Developer
Singapore Singapore
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161021.1 | Last Updated 19 Aug 2003
Article Copyright 2003 by Lai Shiaw San Kent
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid