/
generic_allocator.hpp
50 lines (37 loc) · 1.28 KB
/
generic_allocator.hpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef FALCON_MEMORY_GENERIC_ALLOCATOR_HPP
#define FALCON_MEMORY_GENERIC_ALLOCATOR_HPP
#include <falcon/parameter/parameter_index.hpp>
#include <falcon/memory/allocator_rebind.hpp>
#include <falcon/memory/construct.hpp>
#include <falcon/memory/destroy.hpp>
#include <memory>
namespace falcon {
template<class T, class AllocBase = std::allocator<T> >
class generic_allocator
: public allocator_rebind_t<AllocBase, T>
{
typedef allocator_rebind_t<AllocBase, T> allocator_base;
public:
typedef typename allocator_base::pointer pointer;
typedef typename allocator_base::size_type size_type;
typedef typename allocator_base::const_pointer const_pointer;
typedef typename allocator_base::const_reference const_reference;
template<class U, class NewAllocBase = AllocBase>
struct rebind
{ typedef generic_allocator<U, NewAllocBase> other; };
generic_allocator() = default;
generic_allocator(const generic_allocator& other) = default;
template<class U>
generic_allocator(const generic_allocator<U>& other)
noexcept(noexcept(allocator_base(other)))
: allocator_base(other)
{}
template<class U, class... Args>
void construct(U* p, Args&&... args)
{ ::falcon::construct(p, std::forward<Args>(args)...); }
template<typename U>
void destroy(U* p)
{ ::falcon::destroy(p); }
};
}
#endif