The [[no_unique_address]] Attribute

Understand the use of the '[[no_unique_address]]' attribute in C++20.

We'll cover the following

The story of optimization goes on with the new attribute [[no_unique_address]]. This time the optimization addresses space instead of execution time.

Introduction

[[no_unique_address]] expresses that this data member of a class need not have an address distinct from all other non-static data members of its class. Consequently, if the member has an empty type, the compiler can optimize it to occupy no memory.

Example

The following program exemplifies the usage of the new attribute.

Get hands-on with 1400+ tech skills courses.