/****************************************************************************** Trick Library 'ax' 補助割り付け子クラステンプレートヘッダファイル Copyright(C) 2008 Wraith. All rights reserved. Coded by Wraith in Jun 10, 2008. ******************************************************************************/ /////////////////////////////////////////////////////////////////////////////// // // ■ axmemory.h // http://tricklib.com/cxx/ax/axmemory.h // // □ 関連ファイル // http://tricklib.com/cxx/ax/axconfig.h // http://tricklib.com/cxx/ax/axexcept.h // http://tricklib.com/cxx/ax/axiterat.h // http://tricklib.com/cxx/ax/axstring.h // // □ ライセンス情報 // http://tricklib.com/license.htm // // ★ このファイルはC++標準ライブラリの 相当のものになり、規格票 //  (ISO/IEC 14882, JIS X 3014)の 20 章に基づき実装されています。 // #if !defined(TRICKLIB_AX_AXMEMORY_H) #define TRICKLIB_AX_AXMEMORY_H #include "axconfig.h" #include #if defined(TRICKLIB_AX_ALLOCATOR_USE_MALLOC) #include #else #include #endif namespace tricklib { namespace ax { template class allocator; // void に対する特殊化 //template<> class allocator class void_allocator { public: typedef void * pointer; typedef const void * const_pointer; // void への参照のメンバはない。 typedef void value_type; //template struct rebind { typedef allocator other; }; }; template class allocator { int dummy; public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T * pointer; typedef const T * const_pointer; typedef T& reference; typedef const T & const_reference; typedef T value_type; //template struct rebind { typedef allocator other; }; allocator() { } allocator(const allocator &) { } //template allocator(const allocator&); ~allocator() { } pointer address(reference x) const { return &x; } const_pointer address(const_reference x) const { return &x; } pointer allocate(size_type n, void_allocator::const_pointer hint = 0) { #if defined(TRICKLIB_AX_ALLOCATOR_USE_MALLOC) return static_cast(malloc(n *sizeof(T))); #else return static_cast(::operator new(n *sizeof(T))); #endif } void deallocate(pointer p, size_type n) { #if defined(TRICKLIB_AX_ALLOCATOR_USE_MALLOC) free(p); #else ::operator delete((void *)p); #endif } size_type max_size() const { return TRICKLIB_AX_ALLOCATOR_MAX_MEMORY /sizeof(T); } void construct(pointer p, const T& val) { new (static_cast(p)) T(val); } void destroy(pointer p) { static_cast(p)->~T(); } }; } } #endif // !defined(TRICKLIB_AX_AXMEMORY_H) /****************************************************************************** □■□■ Wraith the Trickster □■□■ ■□■□ 〜I'll go with heaven's advantage and fool's wisdom.〜 ■□■□ ******************************************************************************/