Implementations are allowed to make optional<indirect<T>> the size of a pointer, and high quality ones will do. See this comment from one of the original designers.
At least GCC hasn't done this... I hope it's not too late for them to reconsider.
I have a personal C++26 implementation of optional that implements constexpr niche/tombstone optimizations, so it is at least possible. You need std::is_within_lifetime for constexpr support though.
Thanks for digging that out. Now, with the other reply, that looks like conflicting information - so i guess that issue will circle the skies for a decade. Still, we can use our own.
I was partially right, partially wrong. The committee indeed voted to remove requiring such a specialization, but as jiixyj says that doesn't preclude such a specialization, so implementations are free to do so if they wish. However, I still think once implementations settle on specializing or not they're going to be stuck with that decision as changing that later will impact object size and therefore ABI.
View all comments
Show parent comment
5
u/ts826848 Aug 14 '26
The committee already voted to remove such a specialization as I detailed here, and I think ABI compatibility precludes adding a specialization later.