// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #pragma once #include "new.h" namespace jitstd { template class allocator; template <> class allocator { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef void* pointer; typedef const void* const_pointer; typedef void value_type; template struct rebind { typedef allocator allocator; }; private: allocator(); public: inline allocator(CompAllocator* pAlloc); template inline allocator(const allocator& alloc); inline allocator(const allocator& alloc); template inline allocator& operator=(const allocator& alloc); private: CompAllocator* m_pAlloc; template friend class allocator; }; allocator::allocator(CompAllocator* pAlloc) : m_pAlloc(pAlloc) { } allocator::allocator(const allocator& alloc) : m_pAlloc(alloc.m_pAlloc) { } template allocator::allocator(const allocator& alloc) : m_pAlloc(alloc.m_pAlloc) { } template allocator& allocator::operator=(const allocator& alloc) { m_pAlloc = alloc.m_pAlloc; return *this; } template class allocator { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef T& reference; typedef const T* const_pointer; typedef const T& const_reference; typedef T value_type; private: allocator(); public: allocator(CompAllocator* pAlloc); template allocator(const allocator& alloc); allocator(const allocator& alloc); template allocator& operator=(const allocator& alloc); pointer address(reference val); const_pointer address(const_reference val) const; pointer allocate(size_type count, allocator::const_pointer hint = nullptr); void construct(pointer ptr, const_reference val); void deallocate(pointer ptr, size_type size); void destroy(pointer ptr); size_type max_size() const; template struct rebind { typedef allocator allocator; }; private: CompAllocator* m_pAlloc; template friend class allocator; }; } // end of namespace jitstd namespace jitstd { template allocator::allocator(CompAllocator* pAlloc) : m_pAlloc(pAlloc) { } template template allocator::allocator(const allocator& alloc) : m_pAlloc(alloc.m_pAlloc) { } template allocator::allocator(const allocator& alloc) : m_pAlloc(alloc.m_pAlloc) { } template template allocator& allocator::operator=(const allocator& alloc) { m_pAlloc = alloc.m_pAlloc; return *this; } template typename allocator::pointer allocator::address(reference val) { return &val; } template typename allocator::const_pointer allocator::address(const_reference val) const { return &val; } template T* allocator::allocate(size_type count, allocator::const_pointer hint) { return (pointer) m_pAlloc->Alloc(sizeof(value_type) * count); } template void allocator::construct(pointer ptr, const_reference val) { new (ptr, placement_t()) value_type(val); } template void allocator::deallocate(pointer ptr, size_type size) { // m_pAlloc->Free(ptr); } template void allocator::destroy(pointer ptr) { ptr->~T(); } template typename allocator::size_type allocator::max_size() const { return (size_type) -1; } } // end of namespace jitstd