Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
StealthAllocator.hpp
Go to the documentation of this file.
1
6/*
7 * Author: Radovan Cerveny
8 */
9
10#pragma once
11
12#include <memory>
13#include <cstddef>
14#include "../measurements/MeasurementNew.hpp"
15
16namespace measurements {
17
18template < typename T >
20public:
21 using value_type = T;
22 using pointer = T *;
23 using const_pointer = const T *;
24 using reference = T &;
25 using const_reference = const T &;
26 using size_type = std::size_t;
27 using difference_type = std::ptrdiff_t;
28
29 template < typename U >
31
32 stealth_allocator ( ) = default;
33
34 template < typename U >
36
38 return static_cast < pointer > ( operator new( n * sizeof ( T ), false ) );
39 }
40
42 operator delete( ptr, false );
43 }
44
45 void destroy ( pointer p ) {
46 p->~T ( );
47 }
48
49 template < class ... Args >
50 void construct ( pointer p, Args && ... args ) {
51 ::new ( static_cast < void * > ( p ) ) T ( std::forward < Args > ( args ) ... );
52 }
53
54};
55
56template < typename T, typename U >
58 return true;
59}
60
61template < typename T, typename U >
63 return false;
64}
65
66}
67
Definition: StealthAllocator.hpp:19
void construct(pointer p, Args &&... args)
Definition: StealthAllocator.hpp:50
void destroy(pointer p)
Definition: StealthAllocator.hpp:45
T * pointer
Definition: StealthAllocator.hpp:22
std::size_t size_type
Definition: StealthAllocator.hpp:26
const T & const_reference
Definition: StealthAllocator.hpp:25
T value_type
Definition: StealthAllocator.hpp:21
std::ptrdiff_t difference_type
Definition: StealthAllocator.hpp:27
pointer allocate(size_type n)
Definition: StealthAllocator.hpp:37
void deallocate(pointer ptr, size_type)
Definition: StealthAllocator.hpp:41
const T * const_pointer
Definition: StealthAllocator.hpp:23
T & reference
Definition: StealthAllocator.hpp:24
stealth_allocator(const stealth_allocator< U > &)
Definition: StealthAllocator.hpp:35
Definition: StealthAllocator.hpp:16
bool operator==(const stealth_allocator< T > &, const stealth_allocator< U > &)
Definition: StealthAllocator.hpp:57
bool operator!=(const stealth_allocator< T > &, const stealth_allocator< U > &)
Definition: StealthAllocator.hpp:62
Definition: StealthAllocator.hpp:30