changed code for old compilers
This commit is contained in:
		| @ -34,23 +34,26 @@ | |||||||
| #include <qse/types.h> | #include <qse/types.h> | ||||||
| #include <qse/macros.h> | #include <qse/macros.h> | ||||||
|  |  | ||||||
| // The QSE_CPP_CALL_DESTRUCTOR() macro calls a destructor explicitly. |  | ||||||
| // The QSE_CPP_CALL_PLACEMENT_DELETE1() macro calls the global operator delete |  | ||||||
| // with 1 extra argument given. |  | ||||||
|  |  | ||||||
| #if (__cplusplus >= 201103L) // C++11 | #if (__cplusplus >= 201103L) // C++11 | ||||||
|  |  | ||||||
| 	/// The QSE_ENABLE_CPP11_MOVE macro enables C++11 move semantics | 	/// The QSE_CPP_ENABLE_CPP1_MOVE macro enables C++11 move semantics | ||||||
| 	/// in various classes. | 	/// in various classes. | ||||||
| 	#define QSE_ENABLE_CPP11_MOVE 1 | 	#define QSE_CPP_ENABLE_CPP1_MOVE 1 | ||||||
|  |  | ||||||
|  | 	// The QSE_CPP_CALL_DESTRUCTOR() macro calls a destructor explicitly. | ||||||
| 	#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) | 	#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) | ||||||
|  |  | ||||||
|  | 	// The QSE_CPP_CALL_PLACEMENT_DELETE1() macro calls the global operator delete | ||||||
|  | 	// with 1 extra argument given. | ||||||
| 	#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1))) | 	#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1))) | ||||||
|  |  | ||||||
|  | 	#define QSE_CPP_TEMPLATE_QUALIFIER template | ||||||
|  |  | ||||||
| #elif (__cplusplus >= 199711L) // C++98 | #elif (__cplusplus >= 199711L) // C++98 | ||||||
|  |  | ||||||
| 	#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) | 	#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) | ||||||
| 	#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1))) | 	#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1))) | ||||||
|  | 	#define QSE_CPP_TEMPLATE_QUALIFIER template | ||||||
|  |  | ||||||
| #else | #else | ||||||
|  |  | ||||||
| @ -69,6 +72,7 @@ | |||||||
|  |  | ||||||
| 		#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->class_name::~class_name()) | 		#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->class_name::~class_name()) | ||||||
| 		#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1))) | 		#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1))) | ||||||
|  | 		#define QSE_CPP_TEMPLATE_QUALIFIER template | ||||||
|  |  | ||||||
| 	#elif defined(__WATCOMC__) | 	#elif defined(__WATCOMC__) | ||||||
| 		// WATCOM has a problem with this syntax. | 		// WATCOM has a problem with this syntax. | ||||||
| @ -76,18 +80,41 @@ | |||||||
| 		// But it doesn't support operator delete overloading. | 		// But it doesn't support operator delete overloading. | ||||||
|  |  | ||||||
| 		#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) | 		#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) | ||||||
| 		#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator_delete ((ptr), (arg1))) | 		#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::qse_operator_delete((ptr), (arg1))) | ||||||
|  |  | ||||||
|  | 		// When  the name of a member template specialization appears after .  or | ||||||
|  | 		// -> in a postfix-expression, or after :: in a qualified-id that explic- | ||||||
|  | 		// itly  depends on a template-argument (_temp.dep_), the member template | ||||||
|  | 		// name must be prefixed by the keyword template.  Otherwise the name  is | ||||||
|  | 		// assumed to name a non-template.  [Example: | ||||||
|  | 		// 		class X { | ||||||
|  | 		// 		public: | ||||||
|  | 		// 			   template<size_t> X* alloc(); | ||||||
|  | 		// 		}; | ||||||
|  | 		// 		void f(X* p) | ||||||
|  | 		// 		{ | ||||||
|  | 		// 			   X* p1 = p->alloc<200>(); | ||||||
|  | 		// 					 // ill-formed: < means less than | ||||||
|  | 		// 			   X* p2 = p->template alloc<200>(); | ||||||
|  | 		// 					 // fine: < starts explicit qualification | ||||||
|  | 		// 		} | ||||||
|  | 		// --end example] | ||||||
|  | 		// | ||||||
|  | 		// WATCOM doesn't support this qualifier. | ||||||
|  |  | ||||||
|  | 		#define QSE_CPP_TEMPLATE_QUALIFIER | ||||||
|  | 		#define QSE_CPP_NO_OPERATOR_DELETE_OVERLOADING 1 | ||||||
| 	#else | 	#else | ||||||
|  |  | ||||||
| 		#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) | 		#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) | ||||||
| 		#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1))) | 		#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1))) | ||||||
|  | 		#define QSE_CPP_TEMPLATE_QUALIFIER template | ||||||
|  |  | ||||||
| 	#endif | 	#endif | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
|  |  | ||||||
| 	template<typename T> struct QSE_CPP_RMREF      { typedef T Type; }; | 	template<typename T> struct QSE_CPP_RMREF      { typedef T Type; }; | ||||||
| 	template<typename T> struct QSE_CPP_RMREF<T&>  { typedef T Type; }; | 	template<typename T> struct QSE_CPP_RMREF<T&>  { typedef T Type; }; | ||||||
|  | |||||||
| @ -27,6 +27,9 @@ | |||||||
| #ifndef _QSE_CMN_ARRAY_HPP_ | #ifndef _QSE_CMN_ARRAY_HPP_ | ||||||
| #define _QSE_CMN_ARRAY_HPP_ | #define _QSE_CMN_ARRAY_HPP_ | ||||||
|  |  | ||||||
|  | /// \file | ||||||
|  | /// Provide the Array class. | ||||||
|  |  | ||||||
| #include <qse/Growable.hpp> | #include <qse/Growable.hpp> | ||||||
| #include <qse/cmn/Mmged.hpp> | #include <qse/cmn/Mmged.hpp> | ||||||
|  |  | ||||||
| @ -67,6 +70,9 @@ struct ArrayResizer | |||||||
| /// | /// | ||||||
| /// The Array class provides a dynamically resized array. | /// The Array class provides a dynamically resized array. | ||||||
| /// | /// | ||||||
|  | /// With C++11, the Array class move-contructs values in various context. | ||||||
|  | /// The move constructor of the value must not raise an exception. | ||||||
|  | ///  | ||||||
| template <typename T, typename POSITIONER = ArrayPositioner<T>, typename RESIZER = ArrayResizer > | template <typename T, typename POSITIONER = ArrayPositioner<T>, typename RESIZER = ArrayResizer > | ||||||
| class Array: public Mmged, public Growable | class Array: public Mmged, public Growable | ||||||
| { | { | ||||||
| @ -122,7 +128,7 @@ public: | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
|  |  | ||||||
| 	Array (SelfType&& array): | 	Array (SelfType&& array): | ||||||
| 		Mmged(array.getMmgr()), | 		Mmged(array.getMmgr()), | ||||||
| @ -162,7 +168,7 @@ public: | |||||||
| 		return *this; | 		return *this; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	SelfType& operator= (SelfType&& array) | 	SelfType& operator= (SelfType&& array) | ||||||
| 	{ | 	{ | ||||||
| 		if (this != &array) | 		if (this != &array) | ||||||
| @ -230,7 +236,7 @@ protected: | |||||||
| 		return tmp; | 		return tmp; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	T* clone_buffer_by_moving (T* srcbuf, qse_size_t capa, qse_size_t cnt) | 	T* clone_buffer_by_moving (T* srcbuf, qse_size_t capa, qse_size_t cnt) | ||||||
| 	{ | 	{ | ||||||
| 		QSE_ASSERT (capa > 0); | 		QSE_ASSERT (capa > 0); | ||||||
| @ -262,7 +268,8 @@ protected: | |||||||
| 				// if move-contruction ended up with an exception, | 				// if move-contruction ended up with an exception, | ||||||
| 				// the original array can get into an unknown state eventually. | 				// the original array can get into an unknown state eventually. | ||||||
| 				// i don't attempt to restore the moved object as an exception | 				// i don't attempt to restore the moved object as an exception | ||||||
| 				// may be raised during restoration. | 				// may be raised during restoration. i don't implement noexcept | ||||||
|  | 				// check yet. | ||||||
| 				// | 				// | ||||||
| 				// TODO: reconsider if this unwinding is needed | 				// TODO: reconsider if this unwinding is needed | ||||||
| 				//try { new((QSE::Mmgr*)QSE_NULL, &srcbuf[index]) T((T&&)tmp[index]); } | 				//try { new((QSE::Mmgr*)QSE_NULL, &srcbuf[index]) T((T&&)tmp[index]); } | ||||||
| @ -299,7 +306,7 @@ protected: | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	void put_item_by_moving (qse_size_t index, T&& value) | 	void put_item_by_moving (qse_size_t index, T&& value) | ||||||
| 	{ | 	{ | ||||||
| 		if (index >= this->count) | 		if (index >= this->count) | ||||||
| @ -425,7 +432,7 @@ public: | |||||||
| 		this->update (index, value); | 		this->update (index, value); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	void setValueAt (qse_size_t index, T&& value) | 	void setValueAt (qse_size_t index, T&& value) | ||||||
| 	{ | 	{ | ||||||
| 		this->update (index, QSE_CPP_RVREF(value)); | 		this->update (index, QSE_CPP_RVREF(value)); | ||||||
| @ -459,7 +466,7 @@ protected: | |||||||
| 			// shift the existing elements to the back by one slot. | 			// shift the existing elements to the back by one slot. | ||||||
| 			for (qse_size_t i = this->count; i > index; i--)  | 			for (qse_size_t i = this->count; i > index; i--)  | ||||||
| 			{ | 			{ | ||||||
| 			#if defined(QSE_ENABLE_CPP11_MOVE) | 			#if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 				this->put_item_by_moving (i, QSE_CPP_RVREF(this->buffer[i - 1]));  | 				this->put_item_by_moving (i, QSE_CPP_RVREF(this->buffer[i - 1]));  | ||||||
| 			#else | 			#else | ||||||
| 				this->put_item (i, this->buffer[i - 1]);  | 				this->put_item (i, this->buffer[i - 1]);  | ||||||
| @ -496,7 +503,7 @@ public: | |||||||
| 		return index; | 		return index; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	qse_size_t insert (qse_size_t index, T&& value) | 	qse_size_t insert (qse_size_t index, T&& value) | ||||||
| 	{ | 	{ | ||||||
| 		// Unlike insert() in RedBlackTree and HashList, | 		// Unlike insert() in RedBlackTree and HashList, | ||||||
| @ -523,7 +530,7 @@ public: | |||||||
| 		return index; | 		return index; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	qse_size_t update (qse_size_t index, T&& value) | 	qse_size_t update (qse_size_t index, T&& value) | ||||||
| 	{ | 	{ | ||||||
| 		QSE_ASSERT (index < this->count); | 		QSE_ASSERT (index < this->count); | ||||||
| @ -541,7 +548,7 @@ public: | |||||||
| 			return this->insert (index, value); | 			return this->insert (index, value); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	qse_size_t upsert (qse_size_t index, T&& value) | 	qse_size_t upsert (qse_size_t index, T&& value) | ||||||
| 	{ | 	{ | ||||||
| 		if (index < this->count) | 		if (index < this->count) | ||||||
| @ -559,7 +566,7 @@ public: | |||||||
| 			return this->insert (index, value); | 			return this->insert (index, value); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	qse_size_t ensert (qse_size_t index, T&& value) | 	qse_size_t ensert (qse_size_t index, T&& value) | ||||||
| 	{ | 	{ | ||||||
| 		if (index < this->count) | 		if (index < this->count) | ||||||
| @ -693,7 +700,7 @@ public: | |||||||
| 			qse_size_t cnt = this->count; | 			qse_size_t cnt = this->count; | ||||||
| 			if (cnt > capa) cnt = capa; | 			if (cnt > capa) cnt = capa; | ||||||
|  |  | ||||||
| 		#if defined(QSE_ENABLE_CPP11_MOVE) | 		#if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 			T* tmp = this->clone_buffer_by_moving (this->buffer, capa, cnt); | 			T* tmp = this->clone_buffer_by_moving (this->buffer, capa, cnt); | ||||||
| 		#else | 		#else | ||||||
| 			T* tmp = this->clone_buffer (this->buffer, capa, cnt); | 			T* tmp = this->clone_buffer (this->buffer, capa, cnt); | ||||||
|  | |||||||
| @ -135,7 +135,7 @@ public: | |||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	BinaryHeap (SelfType& heap): ParentType (heap) | 	BinaryHeap (SelfType& heap): ParentType (heap) | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
| @ -154,7 +154,7 @@ public: | |||||||
| 		return *this; | 		return *this; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	SelfType& operator= (SelfType&& heap) | 	SelfType& operator= (SelfType&& heap) | ||||||
| 	{ | 	{ | ||||||
| 		if (this != &heap) | 		if (this != &heap) | ||||||
| @ -212,7 +212,7 @@ public: | |||||||
| 		return this->sift_up(index); | 		return this->sift_up(index); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	qse_size_t insert (T&& value) | 	qse_size_t insert (T&& value) | ||||||
| 	{ | 	{ | ||||||
| 		qse_size_t index = this->count; | 		qse_size_t index = this->count; | ||||||
| @ -234,7 +234,7 @@ public: | |||||||
| 		return (this->greater_than(value, old))? this->sift_up(index): this->sift_down(index); | 		return (this->greater_than(value, old))? this->sift_up(index): this->sift_down(index); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE) | #if defined(QSE_CPP_ENABLE_CPP1_MOVE) | ||||||
| 	qse_size_t update (qse_size_t index, T&& value) | 	qse_size_t update (qse_size_t index, T&& value) | ||||||
| 	{ | 	{ | ||||||
| 		T old = QSE_CPP_RVREF(this->buffer[index]); | 		T old = QSE_CPP_RVREF(this->buffer[index]); | ||||||
|  | |||||||
| @ -239,7 +239,7 @@ public: | |||||||
| 		//if (!node) return QSE_NULL; | 		//if (!node) return QSE_NULL; | ||||||
| 		//return &node->value; | 		//return &node->value; | ||||||
|  |  | ||||||
| 		PairNode* node = this->pair_list.template heterofindNode<K,HASHER,PairHeteroEqualer> (key); | 		PairNode* node = this->pair_list.QSE_CPP_TEMPLATE_QUALIFIER heterofindNode<K,HASHER,PairHeteroEqualer> (key); | ||||||
| 		if (!node) return QSE_NULL; | 		if (!node) return QSE_NULL; | ||||||
| 		Pair& pair = node->value; | 		Pair& pair = node->value; | ||||||
| 		pair.value = value; | 		pair.value = value; | ||||||
| @ -249,11 +249,7 @@ public: | |||||||
| 	Pair* search (const K& key) | 	Pair* search (const K& key) | ||||||
| 	{ | 	{ | ||||||
| 		//PairNode* node = this->pair_list.search (Pair(key)); | 		//PairNode* node = this->pair_list.search (Pair(key)); | ||||||
| 	#if defined(__WATCOMC__) | 		PairNode* node = this->pair_list.QSE_CPP_TEMPLATE_QUALIFIER heterofindNode<K,HASHER,PairHeteroEqualer> (key); | ||||||
| 		PairNode* node = this->pair_list.heterofindNode<K,HASHER,PairHeteroEqualer> (key); |  | ||||||
| 	#else |  | ||||||
| 		PairNode* node = this->pair_list.template heterofindNode<K,HASHER,PairHeteroEqualer> (key); |  | ||||||
| 	#endif |  | ||||||
| 		if (!node) return QSE_NULL; | 		if (!node) return QSE_NULL; | ||||||
| 		return &node->value; | 		return &node->value; | ||||||
| 	} | 	} | ||||||
| @ -261,22 +257,14 @@ public: | |||||||
| 	int remove (const K& key) | 	int remove (const K& key) | ||||||
| 	{ | 	{ | ||||||
| 		//return this->pair_list.remove (Pair(key)); | 		//return this->pair_list.remove (Pair(key)); | ||||||
| 	#if defined(__WATCOMC__) | 		return this->pair_list.QSE_CPP_TEMPLATE_QUALIFIER heteroremove<K,HASHER,PairHeteroEqualer> (key); | ||||||
| 		return this->pair_list.heteroremove<K,HASHER,PairHeteroEqualer> (key); |  | ||||||
| 	#else |  | ||||||
| 		return this->pair_list.template heteroremove<K,HASHER,PairHeteroEqualer> (key); |  | ||||||
| 	#endif |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template <typename MK, typename MHASHER, typename MEQUALER> | 	template <typename MK, typename MHASHER, typename MEQUALER> | ||||||
| 	Pair* heterosearch (const MK& key) | 	Pair* heterosearch (const MK& key) | ||||||
| 	{ | 	{ | ||||||
| 		typedef MHeteroEqualer<MK,MEQUALER> MEqualer; | 		typedef MHeteroEqualer<MK,MEQUALER> MEqualer; | ||||||
| 	#if defined(__WATCOMC__) | 		PairNode* node = this->pair_list.QSE_CPP_TEMPLATE_QUALIFIER heterosearch<MK,MHASHER,MEqualer> (key); | ||||||
| 		PairNode* node = this->pair_list.heterosearch<MK,MHASHER,MEqualer> (key); |  | ||||||
| 	#else |  | ||||||
| 		PairNode* node = this->pair_list.template heterosearch<MK,MHASHER,MEqualer> (key); |  | ||||||
| 	#endif |  | ||||||
| 		if (!node) return QSE_NULL; | 		if (!node) return QSE_NULL; | ||||||
| 		return &node->value; | 		return &node->value; | ||||||
| 	} | 	} | ||||||
| @ -285,7 +273,7 @@ public: | |||||||
| 	const Pair* heterosearch (const MK& key) const | 	const Pair* heterosearch (const MK& key) const | ||||||
| 	{ | 	{ | ||||||
| 		typedef MHeteroEqualer<MK,MEQUALER> MEqualer; | 		typedef MHeteroEqualer<MK,MEQUALER> MEqualer; | ||||||
| 		PairNode* node = this->pair_list.template heterosearch<MK,MHASHER,MEqualer> (key); | 		PairNode* node = this->pair_list.QSE_CPP_TEMPLATE_QUALIFIER heterosearch<MK,MHASHER,MEqualer> (key); | ||||||
| 		if (!node) return QSE_NULL; | 		if (!node) return QSE_NULL; | ||||||
| 		return &node->value; | 		return &node->value; | ||||||
| 	} | 	} | ||||||
| @ -294,7 +282,7 @@ public: | |||||||
| 	int heteroremove (const MK& key) | 	int heteroremove (const MK& key) | ||||||
| 	{ | 	{ | ||||||
| 		typedef MHeteroEqualer<MK,MEQUALER> MEqualer; | 		typedef MHeteroEqualer<MK,MEQUALER> MEqualer; | ||||||
| 		return this->pair_list.template heteroremove<MK,MHASHER,MEqualer> (key); | 		return this->pair_list.QSE_CPP_TEMPLATE_QUALIFIER heteroremove<MK,MHASHER,MEqualer> (key); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void clear (bool clear_mpool = false) | 	void clear (bool clear_mpool = false) | ||||||
|  | |||||||
| @ -176,7 +176,11 @@ QSE_END_NAMESPACE(QSE) | |||||||
|  |  | ||||||
| QSE_EXPORT void* operator new (qse_size_t size, QSE::Mmgr* mmgr); | QSE_EXPORT void* operator new (qse_size_t size, QSE::Mmgr* mmgr); | ||||||
|  |  | ||||||
|  | #if defined(QSE_CPP_NO_OPERATOR_DELETE_OVERLOADING) | ||||||
|  | QSE_EXPORT void qse_operator_delete (void* ptr, QSE::Mmgr* mmgr); | ||||||
|  | #else | ||||||
| QSE_EXPORT void operator delete (void* ptr, QSE::Mmgr* mmgr); | QSE_EXPORT void operator delete (void* ptr, QSE::Mmgr* mmgr); | ||||||
|  | #endif | ||||||
|  |  | ||||||
| QSE_EXPORT void* operator new (qse_size_t size, QSE::Mmgr* mmgr, void* existing_ptr); | QSE_EXPORT void* operator new (qse_size_t size, QSE::Mmgr* mmgr, void* existing_ptr); | ||||||
|  |  | ||||||
|  | |||||||
| @ -126,7 +126,11 @@ QSE_END_NAMESPACE(QSE) | |||||||
|  |  | ||||||
| QSE_EXPORT void* operator new (qse_size_t size, QSE::Mpool* mp); | QSE_EXPORT void* operator new (qse_size_t size, QSE::Mpool* mp); | ||||||
|  |  | ||||||
|  | #if defined(QSE_CPP_NO_OPERATOR_DELETE_OVERLOADING) | ||||||
|  | QSE_EXPORT void qse_operator_delete (void* ptr, QSE::Mpool* mp); | ||||||
|  | #else | ||||||
| QSE_EXPORT void operator delete (void* ptr, QSE::Mpool* mp); | QSE_EXPORT void operator delete (void* ptr, QSE::Mpool* mp); | ||||||
|  | #endif | ||||||
|  |  | ||||||
| QSE_EXPORT void* operator new (qse_size_t size, QSE::Mpool* mp, void* existing_ptr); | QSE_EXPORT void* operator new (qse_size_t size, QSE::Mpool* mp, void* existing_ptr); | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -206,7 +206,7 @@ public: | |||||||
| 		//if (!node) return QSE_NULL; | 		//if (!node) return QSE_NULL; | ||||||
| 		//return &node->value; | 		//return &node->value; | ||||||
|  |  | ||||||
| 		PairNode* node = this->pair_tree.template heterofindNode<K,PairHeteroComparator> (key); | 		PairNode* node = this->pair_tree.QSE_CPP_TEMPLATE_QUALIFIER heterofindNode<K,PairHeteroComparator> (key); | ||||||
| 		if (!node) return QSE_NULL; | 		if (!node) return QSE_NULL; | ||||||
| 		Pair& pair = node->value; | 		Pair& pair = node->value; | ||||||
| 		pair.value = value; | 		pair.value = value; | ||||||
| @ -216,7 +216,7 @@ public: | |||||||
| 	Pair* search (const K& key) | 	Pair* search (const K& key) | ||||||
| 	{ | 	{ | ||||||
| 		//PairNode* node = this->pair_tree.update (Pair(key)); | 		//PairNode* node = this->pair_tree.update (Pair(key)); | ||||||
| 		PairNode* node = this->pair_tree.template heterofindNode<K,PairHeteroComparator> (key); | 		PairNode* node = this->pair_tree.QSE_CPP_TEMPLATE_QUALIFIER heterofindNode<K,PairHeteroComparator> (key); | ||||||
| 		if (!node) return QSE_NULL; | 		if (!node) return QSE_NULL; | ||||||
| 		return &node->value; | 		return &node->value; | ||||||
| 	} | 	} | ||||||
| @ -224,14 +224,14 @@ public: | |||||||
| 	int remove (const K& key) | 	int remove (const K& key) | ||||||
| 	{ | 	{ | ||||||
| 		//return this->pair_tree.remove (Pair(key)); | 		//return this->pair_tree.remove (Pair(key)); | ||||||
| 		return this->pair_tree.template heteroremove<K,PairHeteroComparator> (key); | 		return this->pair_tree.QSE_CPP_TEMPLATE_QUALIFIER heteroremove<K,PairHeteroComparator> (key); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template <typename MK, typename MCOMPARATOR> | 	template <typename MK, typename MCOMPARATOR> | ||||||
| 	Pair* heterosearch (const MK& key) | 	Pair* heterosearch (const MK& key) | ||||||
| 	{ | 	{ | ||||||
| 		typedef MHeteroComparator<MK,MCOMPARATOR> MComparator; | 		typedef MHeteroComparator<MK,MCOMPARATOR> MComparator; | ||||||
| 		PairNode* node = this->pair_tree.template heterosearch<MK,MComparator> (key); | 		PairNode* node = this->pair_tree.QSE_CPP_TEMPLATE_QUALIFIER heterosearch<MK,MComparator> (key); | ||||||
| 		if (!node) return QSE_NULL; | 		if (!node) return QSE_NULL; | ||||||
| 		return &node->value; | 		return &node->value; | ||||||
| 	} | 	} | ||||||
| @ -240,7 +240,7 @@ public: | |||||||
| 	const Pair* heterosearch (const MK& key) const | 	const Pair* heterosearch (const MK& key) const | ||||||
| 	{ | 	{ | ||||||
| 		typedef MHeteroComparator<MK,MCOMPARATOR> MComparator; | 		typedef MHeteroComparator<MK,MCOMPARATOR> MComparator; | ||||||
| 		PairNode* node = this->pair_tree.template heterosearch<MK,MComparator> (key); | 		PairNode* node = this->pair_tree.QSE_CPP_TEMPLATE_QUALIFIER heterosearch<MK,MComparator> (key); | ||||||
| 		if (!node) return QSE_NULL; | 		if (!node) return QSE_NULL; | ||||||
| 		return &node->value; | 		return &node->value; | ||||||
| 	} | 	} | ||||||
| @ -249,7 +249,7 @@ public: | |||||||
| 	int heteroremove (const MK& key) | 	int heteroremove (const MK& key) | ||||||
| 	{ | 	{ | ||||||
| 		typedef MHeteroComparator<MK,MCOMPARATOR> MComparator; | 		typedef MHeteroComparator<MK,MCOMPARATOR> MComparator; | ||||||
| 		return this->pair_tree.template heteroremove<MK,MComparator> (key); | 		return this->pair_tree.QSE_CPP_TEMPLATE_QUALIFIER heteroremove<MK,MComparator> (key); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void clear (bool clear_mpool = false) | 	void clear (bool clear_mpool = false) | ||||||
|  | |||||||
| @ -971,7 +971,7 @@ public: | |||||||
| 	template <typename MT, typename MCOMPARATOR> | 	template <typename MT, typename MCOMPARATOR> | ||||||
| 	int heteroremove (const MT& datum) | 	int heteroremove (const MT& datum) | ||||||
| 	{ | 	{ | ||||||
| 		Node* node = this->template heterofind_node<MT,MCOMPARATOR> (datum); | 		Node* node = this->QSE_CPP_TEMPLATE_QUALIFIER heterofind_node<MT,MCOMPARATOR> (datum); | ||||||
| 		if (node == QSE_NULL) return -1; | 		if (node == QSE_NULL) return -1; | ||||||
|  |  | ||||||
| 		this->remove_node (node); | 		this->remove_node (node); | ||||||
|  | |||||||
| @ -75,7 +75,11 @@ void* operator new (qse_size_t size, QSE::Mmgr* mmgr) | |||||||
| 	return mmgr->allocate (size); | 	return mmgr->allocate (size); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #if defined(QSE_CPP_NO_OPERATOR_DELETE_OVERLOADING) | ||||||
|  | void qse_operator_delete (void* ptr, QSE::Mmgr* mmgr) | ||||||
|  | #else | ||||||
| void operator delete (void* ptr, QSE::Mmgr* mmgr) | void operator delete (void* ptr, QSE::Mmgr* mmgr) | ||||||
|  | #endif | ||||||
| { | { | ||||||
| 	mmgr->dispose (ptr); | 	mmgr->dispose (ptr); | ||||||
| } | } | ||||||
|  | |||||||
| @ -203,14 +203,19 @@ void* operator new (qse_size_t size, QSE::Mpool* mp) | |||||||
| 	use_mmgr: | 	use_mmgr: | ||||||
| 		// when the memory pool is not enabled, it goes through  | 		// when the memory pool is not enabled, it goes through  | ||||||
| 		// the memory manager directly and it honors the size argument. | 		// the memory manager directly and it honors the size argument. | ||||||
| 		return ::operator new(size, mp->getMmgr()); | 		//return ::operator new(size, mp->getMmgr()); | ||||||
|  | 		return mp->getMmgr()->allocate(size); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #if defined(QSE_CPP_NO_OPERATOR_DELETE_OVERLOADING) | ||||||
|  | void qse_operator_delete (void* ptr, QSE::Mpool* mp) | ||||||
|  | #else | ||||||
| void operator delete (void* ptr, QSE::Mpool* mp) | void operator delete (void* ptr, QSE::Mpool* mp) | ||||||
|  | #endif | ||||||
| { | { | ||||||
| 	if (mp->isEnabled()) mp->dispose(ptr); | 	if (mp->isEnabled()) mp->dispose(ptr); | ||||||
| 	else ::operator delete (ptr, mp->getMmgr()); | 	else mp->getMmgr()->dispose(ptr); | ||||||
| } | } | ||||||
|  |  | ||||||
| void* operator new (qse_size_t size, QSE::Mpool* mp, void* existing_ptr) | void* operator new (qse_size_t size, QSE::Mpool* mp, void* existing_ptr) | ||||||
|  | |||||||
| @ -19,7 +19,8 @@ printf ("constructor %d\n", q); | |||||||
| printf ("copy constructor %d\n", *q.x); | printf ("copy constructor %d\n", *q.x); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE)  |  | ||||||
|  | #if defined(QSE_CPP_ENABLE_CPP1_MOVE)  | ||||||
| 	Julia (Julia&& q) | 	Julia (Julia&& q) | ||||||
| 	{ | 	{ | ||||||
| printf ("move constructor %d\n", *q.x); | printf ("move constructor %d\n", *q.x); | ||||||
| @ -50,7 +51,7 @@ printf ("operator= %d\n", *q.x); | |||||||
| 		return *this; | 		return *this; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE)  | #if defined(QSE_CPP_ENABLE_CPP1_MOVE)  | ||||||
| 	Julia& operator= (Julia&& q) | 	Julia& operator= (Julia&& q) | ||||||
| 	{ | 	{ | ||||||
| 		if (this != &q) | 		if (this != &q) | ||||||
| @ -68,9 +69,11 @@ printf ("move operator= %d\n", *q.x); | |||||||
| 	int* x; | 	int* x; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | typedef QSE::Array<Julia> JuliaArray; | ||||||
|  |  | ||||||
| int main () | int main () | ||||||
| { | { | ||||||
| 	QSE::Array<Julia> a0; | 	JuliaArray a0; | ||||||
|  |  | ||||||
| 	for (int i = 0; i < 256; i++) | 	for (int i = 0; i < 256; i++) | ||||||
| 	{ | 	{ | ||||||
| @ -83,10 +86,10 @@ int main () | |||||||
| 	a0.remove (2, 5); | 	a0.remove (2, 5); | ||||||
|  |  | ||||||
| 	a0.update (5, Julia(9999)); | 	a0.update (5, Julia(9999)); | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE)  | #if defined(QSE_CPP_ENABLE_CPP1_MOVE)  | ||||||
| 	QSE::Array<Julia> a1 ((QSE::Array<Julia>&&)a0); | 	JuliaArray a1 ((JuliaArray&&)a0); | ||||||
| #else | #else | ||||||
| 	QSE::Array<Julia> a1 (a0); | 	JuliaArray a1 (a0); | ||||||
| #endif | #endif | ||||||
| 	printf ("OK: %d %d\n", (int)a0.getSize(), (int)a1.getSize()); | 	printf ("OK: %d %d\n", (int)a0.getSize(), (int)a1.getSize()); | ||||||
|  |  | ||||||
| @ -96,7 +99,7 @@ int main () | |||||||
| 		printf ("ITEM: %d => %d\n", (int)i, *a1[i].x); | 		printf ("ITEM: %d => %d\n", (int)i, *a1[i].x); | ||||||
| 	} | 	} | ||||||
| 	printf ("----------------\n"); | 	printf ("----------------\n"); | ||||||
| 	a1.rotate (QSE::Array<Julia>::ROTATE_LEFT, 2); | 	a1.rotate (JuliaArray::ROTATE_LEFT, 2); | ||||||
| 	for (qse_size_t i = 0; i < a1.getSize(); i++) | 	for (qse_size_t i = 0; i < a1.getSize(); i++) | ||||||
| 	{ | 	{ | ||||||
| 		printf ("ITEM: %d => %d\n", (int)i, *a1[i].x); | 		printf ("ITEM: %d => %d\n", (int)i, *a1[i].x); | ||||||
|  | |||||||
| @ -19,7 +19,7 @@ public: | |||||||
| 		this->x = new int (*q.x); | 		this->x = new int (*q.x); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE)  | #if defined(QSE_CPP_ENABLE_CPP1_MOVE)  | ||||||
| 	Julia (Julia&& q) | 	Julia (Julia&& q) | ||||||
| 	{ | 	{ | ||||||
| 		this->x = q.x; | 		this->x = q.x; | ||||||
| @ -46,7 +46,7 @@ public: | |||||||
| 		return *this; | 		return *this; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if defined(QSE_ENABLE_CPP11_MOVE)  | #if defined(QSE_CPP_ENABLE_CPP1_MOVE)  | ||||||
| 	Julia& operator= (Julia&& q) | 	Julia& operator= (Julia&& q) | ||||||
| 	{ | 	{ | ||||||
| 		if (this != &q) | 		if (this != &q) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user