Click here to Skip to main content
13,196,126 members (47,808 online)
Click here to Skip to main content
Articles » Languages » C / C++ Language » STL » Downloads


100 bookmarked
Posted 18 Aug 2003

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


About the Author

Lai Shiaw San Kent
Web Developer
Singapore Singapore
No Biography provided

You may also be interested in...

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