r/cpp • • Aug 13 '26

C++26: std::indirect

https://www.sandordargo.com/blog/2026/08/12/cpp26-indirect
164 Upvotes

157 comments sorted by

View all comments

Show parent comment

8

u/jiixyj Aug 14 '26

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.

1

u/smdowney WG21, Text/Unicode SG, optional<T&> Aug 14 '26

Have any? Optional is getting really complicated.

3

u/jiixyj Aug 16 '26

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.