Размещение нового + reventpret_cast + pointer arithmetic = ub?C++

Программы на C++. Форум разработчиков
Anonymous
Размещение нового + reventpret_cast + pointer arithmetic = ub?

Сообщение Anonymous »

Аналогично примеру на странице std :: aligned_storage здесь, представьте, что у меня есть следующее:

Код: Выделить всё

template 
class SlotArray {
static_assert(!std::is_array_v);
static_assert(!std::is_void_v);
using StorageType = std::aligned_storage_t;

public:
template
T* alloc(Args... args) {
std::size_t index = claimIndex();
return ::new(&slots[index]) T(std::forward(args)...);
}

void free(T* value) {
static_assert(sizeof(std::ptrdiff_t) 

Подробнее здесь: [url]https://stackoverflow.com/questions/79493057/placement-new-reinterpret-cast-pointer-arithmetic-ub[/url]

Вернуться в «C++»