r/cpp • Meeting C++ | C++ Evangelist • Oct 17 '26

A quick C++ standard container overview

https://meetingcpp.com/blog/items/A-quick-Cpp-standard-container-overview.html
23 Upvotes

20 comments sorted by

View all comments

6

u/LB-- Professional+Hobbyist Oct 17 '26

Surprising to see span with so little usage, I guess because it didn't make it into C++17? We use gsl::span for that reason, but depending on survey wording I would have answered yes to using std::span anyway.

7

u/meetingcpp Meeting C++ | C++ Evangelist Oct 17 '26

Over time I do see span rise in this question in the yearly results. From 14.5% in 2020 to 40% in 2026.

2

u/fdwr fdwr@github 🔍 Oct 21 '26

I am surprised to see std::deque having so much usage, nearly half of vector, given I have never seen it in any codebases I've worked in. 🤷‍♂️

2

u/LB-- Professional+Hobbyist Oct 21 '26

Not to mention the flawed implementations in most standard library implementations. I remember trying to use it before learning about the implementation quality problem, since in theory it seems like a very useful container. Alas... std::hive can't get here soon enough.

2

u/fdwr fdwr@github 🔍 Oct 21 '26

Ok, I just Ctrl+Shift+F'd on a codebase I frequent, and there is deque usage, but minimal in comparison (std::deque x 32, std::vector x 10'890). 🐝⏳

2

u/Ameisen vemips, avr, rendering, systems Oct 17 '26

std::span does run into the Win64 ABI problem. Not a real concern in most cases but the cost can be noticeable in some cases.

2

u/JNighthawk gamedev Oct 19 '26

the Win64 ABI problem. Not a real concern in most cases but the cost can be noticeable in some cases.

Can you expand on this or link to a source? I'd like to know more about it.

3

u/Ameisen vemips, avr, rendering, systems Oct 19 '26 edited Oct 20 '26

Under SysV and Win64, if you pass a pointer and a size as separate arguments, they'll both be passed by register.

Under SysV, a 16B structure made up of two integer members (like std::span) will be split and also passed by two registers. I can link to the SysV spec, but the argument-passing part is really hard to parse.

Under Win64, though, that structure will instead be passed on the stack.

Structs and unions of size 8, 16, 32, or 64 bits, and __m64 types, are passed as if they were integers of the same size. Structs or unions of other sizes are passed as a pointer to memory allocated by the caller. For these aggregate types passed as a pointer, including __m128, the caller-allocated temporary memory must be 16-byte aligned.

1

u/JNighthawk gamedev Oct 20 '26

Thank you!

1

u/AnyPhotograph7804 Oct 17 '26

The adaptation will be propably slower because many people are used to use references.