89 template <
class OtherElementType>
90 using AllowConversion = std::enable_if_t<std::is_base_of_v<std::remove_pointer_t<ElementType>,
91 std::remove_pointer_t<OtherElementType>>>;
110 template <
typename SizeType, std::enable_if_t<std::is_convertible_v<SizeType,
int>,
int> = 0>
121 template <
typename SizeType, std::enable_if_t<std::is_convertible_v<SizeType,
int>,
int> = 0>
140 other.data =
nullptr;
146 std::swap (data, other.data);
154 template <
class OtherElementType,
bool otherThrowOnFailure,
typename = AllowConversion<OtherElementType>>
156 : data (
reinterpret_cast<ElementType*
> (other.data))
158 other.data =
nullptr;
165 template <
class OtherElementType,
bool otherThrowOnFailure,
typename = AllowConversion<OtherElementType>>
169 data =
reinterpret_cast<ElementType*
> (other.data);
170 other.data =
nullptr;
179 inline operator ElementType*()
const noexcept {
return data; }
197 inline operator void*()
const noexcept {
return static_cast<void*
> (data); }
203 inline operator const void*()
const noexcept {
return static_cast<const void*
> (data); }
215 template <
typename IndexType>
221 template <
typename IndexType>
248 template <
typename SizeType>
258 template <
typename SizeType>
269 template <
typename SizeType>
274 : mallocWrapper (
static_cast<size_t> (
newNumElements) *
sizeof (ElementType));
282 template <
typename SizeType>
300 template <
bool otherBlockThrows>
303 std::swap (data, other.data);
310 template <
typename SizeType>
313 zeromem (data,
sizeof (ElementType) *
static_cast<size_t> (
numElements));
323 template <
typename Functor>
324 static ElementType* wrapper (
size_t size,
Functor&& f)
329 auto* memory =
static_cast<ElementType*
> (f());
331 #if JUCE_EXCEPTIONS_DISABLED
332 jassert (memory !=
nullptr);
334 HeapBlockHelper::ThrowOnFail<throwOnFailure>::checkPointer (memory);
340 static ElementType* mallocWrapper (
size_t size)
342 return wrapper (size, [size] {
return std::malloc (size); });
345 static ElementType* callocWrapper (
size_t num,
size_t size)
347 return wrapper (num * size, [num, size] {
return std::calloc (num, size); });
350 static ElementType* reallocWrapper (
void* ptr,
size_t newSize)
352 return wrapper (newSize, [ptr, newSize] {
return std::realloc (ptr, newSize); });
355 template <
class OtherElementType,
bool otherThrowOnFailure>
359 ElementType* data =
nullptr;
361 #if ! (defined (JUCE_DLL) || defined (JUCE_DLL_BUILD))
362 JUCE_DECLARE_NON_COPYABLE (HeapBlock)
363 JUCE_PREVENT_HEAP_ALLOCATION