11 #ifndef FW_TYPES_LANGUAGE_HELPERS_HPP_ 12 #define FW_TYPES_LANGUAGE_HELPERS_HPP_ 14 #include <type_traits> 37 static_assert(!std::is_array<T>::value,
"Cannot use arrayPlacementNew new for arrays of arrays");
38 static_assert(std::is_constructible<T>::value,
39 "Cannot use arrayPlacementNew on types without a default zero-argument constructor");
40 void* base_pointer =
reinterpret_cast<void*
>(array.
bytes);
42 FW_ASSERT((reinterpret_cast<PlatformPointerCastType>(base_pointer) %
alignof(T)) == 0);
44 T* type_pointer =
static_cast<T*
>(base_pointer);
45 for (
FwSizeType index = 0; index < arraySize; index++) {
46 new (&type_pointer[index]) T();
63 static_assert(!std::is_array<T>::value,
"Cannot use arrayPlacementDestruct new for arrays of arrays");
65 for (
FwSizeType index = 0; index < arraySize; index++) {
66 arrayPointer[index].~T();
70 #endif // FW_TYPES_LANGUAGE_HELPERS_HPP_ PlatformSizeType FwSizeType
void arrayPlacementDestruct(T *arrayPointer, FwSizeType arraySize)
placement delete for arrays
A variable-length byte array.
U8 *const bytes
The bytes.
Implementation of malloc based allocator.
T * arrayPlacementNew(Fw::ByteArray array, FwSizeType arraySize)
placement new for arrays
const FwSizeType size
The size.