Add bare_allocator archetype that implements the minimal possible allocator interface.

llvm-svn: 215691
This commit is contained in:
Eric Fiselier 2014-08-15 04:15:41 +00:00
parent 17fd848bfa
commit e3981b8fac
1 changed files with 29 additions and 1 deletions

View File

@ -10,6 +10,34 @@
#ifndef MIN_ALLOCATOR_H
#define MIN_ALLOCATOR_H
#include <cstddef>
template <class T>
class bare_allocator
{
public:
typedef T value_type;
bare_allocator() {}
template <class U>
bare_allocator(bare_allocator<U>) {}
T* allocate(std::size_t n)
{
return static_cast<T*>(::operator new(n*sizeof(T)));
}
void deallocate(T* p, std::size_t)
{
return ::operator delete(static_cast<void*>(p));
}
friend bool operator==(bare_allocator, bare_allocator) {return true;}
friend bool operator!=(bare_allocator x, bare_allocator y) {return !(x == y);}
};
#if __cplusplus >= 201103L
#include <memory>