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

6

u/LB-- Professional+Hobbyist Aug 14 '26

You can still distinguish that in a single pointer's worth of memory. Since dynamic allocation with alignment is required, you can use one of the alignment bits as a tag for "holds moved-from indirect". It looks like C++29 is getting constexpr support for that trick too.

4

u/ts826848 Aug 14 '26

Yeah, I've been corrected already. I'll edit my comment to make that clearer.

3

u/jiixyj Aug 16 '26

Is there something else needed for this besides std::is_within_lifetime, which is C++26?

I have a constexpr implementation of niche/tombstone optimization that works with clang -std=c++26, but of course it might very well depend on some compiler specific behavior...

2

u/LB-- Professional+Hobbyist Aug 16 '26

Hm for this specific case I think you may be right. The pointer tagging I was referring to is usually for when you also want to still access the live object at the same time as using the alignment bits for additional data, which I suppose isn't needed here.