Blaze 3.9
NullAllocator.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_UTIL_NULLALLOCATOR_H_
36#define _BLAZE_UTIL_NULLALLOCATOR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
44#include <blaze/util/Memory.h>
45#include <blaze/util/Types.h>
46
47
48namespace blaze {
49
50//=================================================================================================
51//
52// CLASS DEFINITION
53//
54//=================================================================================================
55
56//*************************************************************************************************
64template< typename T >
66{
67 public:
68 //**Type definitions****************************************************************************
69 using ValueType = T;
70 using SizeType = size_t;
71 using DifferenceType = ptrdiff_t;
72
73 // STL allocator requirements
77 //**********************************************************************************************
78
79 //**rebind class definition*********************************************************************
82 template< typename U >
83 struct rebind
84 {
86 };
87 //**********************************************************************************************
88
89 //**Constructors********************************************************************************
92 NullAllocator() = default;
93
94 template< typename U >
95 inline NullAllocator( const NullAllocator<U>& );
97 //**********************************************************************************************
98
99 //**Allocation functions************************************************************************
102 inline T* allocate ( size_t numObjects );
103 inline void deallocate( T* ptr, size_t numObjects ) noexcept;
105 //**********************************************************************************************
106};
107//*************************************************************************************************
108
109
110
111
112//=================================================================================================
113//
114// CONSTRUCTOR
115//
116//=================================================================================================
117
118//*************************************************************************************************
123template< typename T >
124template< typename U >
126{
127 MAYBE_UNUSED( allocator );
128}
129//*************************************************************************************************
130
131
132
133
134//=================================================================================================
135//
136// ALLOCATION FUNCTIONS
137//
138//=================================================================================================
139
140//*************************************************************************************************
148template< typename T >
149inline T* NullAllocator<T>::allocate( size_t numObjects )
150{
151 MAYBE_UNUSED( numObjects );
152
153 return static_cast<T*>( nullptr );
154}
155//*************************************************************************************************
156
157
158//*************************************************************************************************
169template< typename T >
170inline void NullAllocator<T>::deallocate( T* ptr, size_t numObjects ) noexcept
171{
172 MAYBE_UNUSED( ptr, numObjects );
173}
174//*************************************************************************************************
175
176
177
178
179//=================================================================================================
180//
181// GLOBAL OPERATORS
182//
183//=================================================================================================
184
185//*************************************************************************************************
188template< typename T1, typename T2 >
189inline bool operator==( const NullAllocator<T1>& lhs, const NullAllocator<T2>& rhs ) noexcept;
190
191template< typename T1, typename T2 >
192inline bool operator!=( const NullAllocator<T1>& lhs, const NullAllocator<T2>& rhs ) noexcept;
194//*************************************************************************************************
195
196
197//*************************************************************************************************
204template< typename T1 // Type of the left-hand side null allocator
205 , typename T2 > // Type of the right-hand side null allocator
206inline bool operator==( const NullAllocator<T1>& lhs, const NullAllocator<T2>& rhs ) noexcept
207{
208 MAYBE_UNUSED( lhs, rhs );
209 return true;
210}
211//*************************************************************************************************
212
213
214//*************************************************************************************************
221template< typename T1 // Type of the left-hand side null allocator
222 , typename T2 > // Type of the right-hand side null allocator
223inline bool operator!=( const NullAllocator<T1>& lhs, const NullAllocator<T2>& rhs ) noexcept
224{
225 MAYBE_UNUSED( lhs, rhs );
226 return false;
227}
228//*************************************************************************************************
229
230} // namespace blaze
231
232#endif
Header file for the MAYBE_UNUSED function template.
Header file for memory allocation and deallocation functionality.
Allocator returning nullptr.
Definition: NullAllocator.h:66
size_t SizeType
Size type of the null allocator.
Definition: NullAllocator.h:70
void deallocate(T *ptr, size_t numObjects) noexcept
Deallocation of memory.
Definition: NullAllocator.h:170
SizeType size_type
Size type of the null allocator.
Definition: NullAllocator.h:75
T ValueType
Type of the allocated values.
Definition: NullAllocator.h:69
ptrdiff_t DifferenceType
Difference type of the null allocator.
Definition: NullAllocator.h:71
ValueType value_type
Type of the allocated values.
Definition: NullAllocator.h:74
T * allocate(size_t numObjects)
Performs no memory allocation and returns nullptr.
Definition: NullAllocator.h:149
DifferenceType difference_type
Difference type of the null allocator.
Definition: NullAllocator.h:76
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
Implementation of the NullAllocator rebind mechanism.
Definition: NullAllocator.h:84
Header file for basic type definitions.