I was trying to write a simple allocation function and I was wondering if this is considered good practice or even correct
template <typename T> T *alloc(size_t count)
{
return static_cast<T *>(::operator new(
sizeof(T) * count,
static_cast<std::align_val_t>(alignof(T)))
);
}
template <typename T> void free(T *ptr, size_t count)
{
::operator delete(
data,
sizeof(T) * count,
static_cast<std::align_val_t>(alignof(T))
);
}
Is it guaranteed that the align_val_t overloads can always be chosen instead of the overloads without align_val_t where the latter would be correct? Does this still hold true for the required behavior of user-replacements of these replaceable overloads?
(Assuming the multiplication on the size does not overflow.)