logoalt Hacker News

tialaramextoday at 6:44 AM1 replyview on HN

> C++ actually did end up evolving the ability to define a zero-sized class without a unique memory address

Did it? Are you talking about the no_unique_address attribute (I had to go look that up because WG21 apparently doesn't care about consistently using or not using separators in attribute names) ? That attribute lets you do the same trick as empty base class but without the ceremony, however it doesn't let you make ZSTs.


Replies

mpynetoday at 2:53 PM

Yes, that's what I'm talking about. It does expand on the empty base object optimization, though it is still not fully generic.

But you can now have multiple zero-sized types as siblings in a struct or class that can be zero-sized, the restriction is that they do have to be different types.