Можно ли использовать [[no_unique_address]] с типами, отличными от POD?C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Можно ли использовать [[no_unique_address]] с типами, отличными от POD?

Сообщение Anonymous »


With the attribute [[no_unique_address]] used for plain old data (POD) arrays like ‘std::size_t[]’ the template specialization for zero structure size could be as small as index member is has, not occupying memory for the data array.

When I do the same with the std::array, this doesn’t work. Most likely because [[no_unique_address]] it can’t handle compound object and this should have done in std::array implementation itself, but as I guess it was developed before [[no_unique_address]] attribute was introduced.

In case I need to have this std::array directly in the structure (no pointers, references, etc.) is there a chance to make [[no_unique_address]] working for std::array as it does for std::size_t[]?

Here is the demo

#include #include using data_type = std::size_t; template struct ExtendableIndexArray { std::size_t index; [[no_unique_address]] std::array data; }; template struct ExtendableIndexPOD { std::size_t index; [[no_unique_address]] data_type data[_data_size]; }; int main() { std::cout

Источник: https://stackoverflow.com/questions/780 ... -pod-types
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

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