cppassist  1.0.0.f4fab4f962ff
C++ sanctuary for small but powerful and frequently required, stand alone features.
allocator.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #ifdef _MSC_VER
5  #pragma warning (push)
6  #pragma warning (disable: 4100) // 'identifier': unreferenced formal parameter
7 #endif
8 
9 
10 #include <cstddef>
11 
12 #include <cppassist/cppassist_api.h>
13 
14 
15 namespace cppassist
16 {
17 
18 
22 template <class T, int N>
23 class CPPASSIST_TEMPLATE_API aligned_allocator
24 {
25 public:
26  typedef T value_type;
27  typedef T& reference;
28  typedef const T& const_reference;
29  typedef T* pointer;
30  typedef const T* const_pointer;
31  typedef size_t size_type;
32  typedef ptrdiff_t difference_type;
33 
34  template <class U>
35  struct rebind
36  {
38  };
39 
40  inline aligned_allocator() throw() {}
41  inline aligned_allocator(const aligned_allocator&) throw() {}
42 
43  template <class U>
44  inline aligned_allocator(const aligned_allocator<U,N>&) throw() {}
45 
46  inline ~aligned_allocator() throw() {}
47 
48  inline pointer address(reference r) { return &r; }
49  inline const_pointer address(const_reference r) const { return &r; }
50 
51  pointer allocate(size_type n, typename std::allocator<void>::const_pointer hint = 0);
52  inline void deallocate(pointer p, size_type);
53 
54  inline void construct(pointer p, const_reference value) { new (p) value_type(value); }
55  inline void destroy(pointer p) { p->~value_type(); }
56 
57  inline size_type max_size() const throw() { return size_type(-1) / sizeof(T); }
58 
59  inline bool operator==(const aligned_allocator&) { return true; }
60  inline bool operator!=(const aligned_allocator& rhs) { return !operator==(rhs); }
61 };
62 
63 
64 } // namespace cppassist
65 
66 
68 
69 #ifdef _MSC_VER
70  #pragma warning (pop)
71 #endif
T * pointer
Definition: allocator.h:29
void destroy(pointer p)
Definition: allocator.h:55
Definition: allocator.h:35
const_pointer address(const_reference r) const
Definition: allocator.h:49
~aligned_allocator()
Definition: allocator.h:46
Definition: ArgumentParser.h:12
aligned_allocator(const aligned_allocator< U, N > &)
Definition: allocator.h:44
bool operator==(const aligned_allocator &)
Definition: allocator.h:59
Definition: allocator.h:23
ptrdiff_t difference_type
Definition: allocator.h:32
const T * const_pointer
Definition: allocator.h:30
void construct(pointer p, const_reference value)
Definition: allocator.h:54
size_type max_size() const
Definition: allocator.h:57
const T & const_reference
Definition: allocator.h:28
aligned_allocator(const aligned_allocator &)
Definition: allocator.h:41
Definition: value.h:14
T & reference
Definition: allocator.h:27
aligned_allocator()
Definition: allocator.h:40
pointer address(reference r)
Definition: allocator.h:48
T value_type
Definition: allocator.h:26
aligned_allocator< U, N > other
Definition: allocator.h:37
bool operator!=(const aligned_allocator &rhs)
Definition: allocator.h:60
size_t size_type
Definition: allocator.h:31