[Bf-committers] MEM_CacheLimiter breaks msvc6 compile repairable!

bjornmose at gmx.net bjornmose at gmx.net
Thu Feb 9 15:21:07 CET 2006


Yupii,

it compiles.

	template<typename _Tp1>
        MEM_Allocator(const MEM_Allocator<_Tp1> __a ) throw() { }

were the evil lines choking msvc6... not needed here .. shrug

the rest was fixing it according
http://www.codeguru.com/Cpp/Cpp/cpp_mfc/stl/article.php/c4079


The following is a version of 

class MEM_Allocator
that compiles on MSVC6 ... not sure if it works flawlessly.
So Peter / Simon will you both please check for obvious stupidity.

Ole


#ifndef __MEM_Allocator_h_included__
#define __MEM_Allocator_h_included__ 1

#include "./../guardedalloc/MEM_guardedalloc.h"

template<class _Tp>
class MEM_Allocator
{
public:
	typedef size_t    size_type;
	typedef ptrdiff_t difference_type;
	typedef _Tp*       pointer;
	typedef const _Tp* const_pointer;
	typedef _Tp&       reference;
	typedef const _Tp& const_reference;
	typedef _Tp        value_type;

	MEM_Allocator<_Tp>& operator=( MEM_Allocator<_Tp> ) { }

/* ************************************
   **************  has no meaning in mscv6  
   ************************************
*/
	/*
	template<typename _Tp1>
        struct rebind { 
		typedef MEM_Allocator<_Tp1> other; 
	};
	*/

/* ************************************
   **************  mscv6 seems to need that 
   ************************************
*/
	char *_Charalloc(size_type n) {
		return (char *)	MEM_mallocN(n,"STL MEM_Allocator ListNode");
	}

	MEM_Allocator() throw() {}
	MEM_Allocator(const MEM_Allocator& __a ) throw() {}


/* ************************************
   ************** duh mscv6 does not like this 
   ************************************
	template<typename _Tp1>
        MEM_Allocator(const MEM_Allocator<_Tp1> __a ) throw() { }
*/

	~MEM_Allocator() throw() {}

	pointer address(reference __x) const { return &__x; }

	const_pointer address(const_reference __x) const { return &__x; }


	// NB: __n is permitted to be 0.  The C++ standard says nothing
	// about what the return value is when __n == 0.
	_Tp* allocate(size_type __n, const void* = 0) {
		_Tp* __ret = 0;
		if (__n)
			__ret = static_cast<_Tp*>(
				MEM_mallocN(__n * sizeof(_Tp),
					    "STL MEM_Allocator"));
		return __ret;
	}

/* ************************************
   ************** mscv6 wants a void pointer here 
   ************************************
   */
	// __p is not permitted to be a null pointer.
	void deallocate(void* __p, size_type){ 
		MEM_freeN(__p);
	}

	size_type max_size() const throw() { 
		return size_t(-1) / sizeof(_Tp); 
	}

	void construct(pointer __p, const _Tp& __val) { 
		new(__p) _Tp(__val); 
	}

	void destroy(pointer __p) { 
	__p->~_Tp(); 
	}
};

#endif

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner


More information about the Bf-committers mailing list