diff options
author | Eric Fiselier <eric@efcs.ca> | 2014-08-15 04:15:41 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2014-08-15 04:15:41 +0000 |
commit | e3981b8faca21fa3212177e2e41eb1aa5bc7da6b (patch) | |
tree | 9e1f68569a303b131bb510da116cc3e18afb2aab /libcxx/test/support/min_allocator.h | |
parent | 17fd848bfafd5ee4dd36887d9c3c8556d0f013fe (diff) | |
download | bcm5719-llvm-e3981b8faca21fa3212177e2e41eb1aa5bc7da6b.tar.gz bcm5719-llvm-e3981b8faca21fa3212177e2e41eb1aa5bc7da6b.zip |
Add bare_allocator archetype that implements the minimal possible allocator interface.
llvm-svn: 215691
Diffstat (limited to 'libcxx/test/support/min_allocator.h')
-rw-r--r-- | libcxx/test/support/min_allocator.h | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/libcxx/test/support/min_allocator.h b/libcxx/test/support/min_allocator.h index f3f08caa556..b643636e178 100644 --- a/libcxx/test/support/min_allocator.h +++ b/libcxx/test/support/min_allocator.h @@ -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> @@ -71,7 +99,7 @@ public: explicit min_pointer(min_pointer<void> p) : ptr_(static_cast<T*>(p.ptr_)) {} explicit operator bool() const {return ptr_ != nullptr;} - + typedef std::ptrdiff_t difference_type; typedef T& reference; typedef T* pointer; |