r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Sep 24 '26
About alignment, struct layout and the cache...
https://meetingcpp.com/blog/items/About-alignment--struct-layout-and-the-cache---.html
36
Upvotes
View all comments
Show parent comment
3
u/SirClueless Sep 25 '26
By the way, I'm looking forward very much to having
std::indirectin the language, because it makes the design of the container described in this article pretty much free: The "dynamic array of pointers" container described here is exactlystd::vector<std::indirect<T>>.When you want pointer-stability and a small object to iterate over, this type of design is already frequently recommended. For example, Abseil recommends using
std::unique_ptr<T>when you want pointer stability of values: https://abseil.io/docs/cpp/guides/container. But usingstd::unique_ptrcomes with all kinds of compromises (especially, no more copy constructor, but also doesn't hash or compare like a value type any more which is also a killer that rules it out for the keys of maps and sets). Now withstd::indirectchoosing whether to put the value inline in the container is nearly a free choice.