1 | /* Used in Boost.MultiIndex tests. |
2 | * |
3 | * Copyright 2003-2018 Joaquin M Lopez Munoz. |
4 | * Distributed under the Boost Software License, Version 1.0. |
5 | * (See accompanying file LICENSE_1_0.txt or copy at |
6 | * http://www.boost.org/LICENSE_1_0.txt) |
7 | * |
8 | * See http://www.boost.org/libs/multi_index for library home page. |
9 | */ |
10 | |
11 | #ifndef BOOST_MULTI_INDEX_TEST_SMALL_ALLOCATOR_HPP |
12 | #define BOOST_MULTI_INDEX_TEST_SMALL_ALLOCATOR_HPP |
13 | |
14 | #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ |
15 | |
16 | template<typename T> |
17 | class small_allocator |
18 | { |
19 | public: |
20 | typedef unsigned char size_type; |
21 | typedef signed char difference_type; |
22 | typedef T* pointer; |
23 | typedef const T* const_pointer; |
24 | typedef void* void_pointer; |
25 | typedef const void* const_void_pointer; |
26 | typedef T& reference; |
27 | typedef const T& const_reference; |
28 | typedef T value_type; |
29 | template<class U>struct rebind{typedef small_allocator<U> other;}; |
30 | |
31 | small_allocator(){} |
32 | small_allocator(const small_allocator<T>&){} |
33 | template<class U>small_allocator(const small_allocator<U>&,int=0){} |
34 | |
35 | pointer allocate(size_type n) |
36 | { |
37 | return pointer((T*)(new char[n*sizeof(T)])); |
38 | } |
39 | |
40 | void deallocate(pointer p,size_type) |
41 | { |
42 | delete[](char *)&*p; |
43 | } |
44 | |
45 | size_type max_size()const{return (size_type)(-1);} |
46 | |
47 | friend bool operator==(const small_allocator&,const small_allocator&) |
48 | { |
49 | return true; |
50 | } |
51 | |
52 | friend bool operator!=(const small_allocator&,const small_allocator&) |
53 | { |
54 | return false; |
55 | } |
56 | }; |
57 | |
58 | #endif |
59 | |