-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathnull_allocator.hpp
More file actions
33 lines (26 loc) · 1011 Bytes
/
null_allocator.hpp
File metadata and controls
33 lines (26 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef BOOST_ARENA_NULL_ALLOCATOR_HPP
#define BOOST_ARENA_NULL_ALLOCATOR_HPP
#include <boost/limits.hpp>
#include <boost/utility.hpp>
namespace boost {
namespace arena {
template<typename T>
struct null_allocator {
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef const T* const_pointer;
typedef const T& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
pointer address(reference x) const { return &x; }
const_pointer address(const_reference x) const { return &x; }
pointer allocate(size_type n, const void *hint=0) { return NULL; }
void deallocate(pointer p, size_type n) {}
size_type max_size() const throw() { return std::numeric_limits<size_type>::max(); }
void construct(pointer p, const_reference val) { new((void*)p) T(val); }
void destroy(pointer p) { ((T*)p)->~T(); }
};
} //namespace arena
} //namespace boost
#endif //BOOST_ARENA_NULL_ALLOCATOR_HPP