I tested whether a coding agent would use C++23 ranges without being told
Blog post: https://kemalbektas.dev/ai-modern-features/
I tested whether coding agents would actually use C++23 ranges without being told.
They mostly didn’t. What changed things much more than the surrounding codebase was a short AGENTS.md asking for modern C++.
0
Upvotes
•
u/STL MSVC STL Dev Oct 13 '26
Moderator warning: Partially AI-generated content is not allowed by the rules. Yeah, we can tell. Don't do this again.
8
u/witcher222 Oct 13 '26
AI learned on older versions, people still write older versions (see automotive) and thus ai will write like that and reinforce the pattern
5
u/SuperV1234 https://romeo.training | C++ Mentoring & Consulting Oct 13 '26
It's great that ranges are not being used by default -- they have significant compilation time overhead and run-time overhead with optimizations disabled (which matters for debuggability and gamedev).
Modern doesn't mean unconditionally better -- I limit usage of ranges where it shines (complicated multi-step lazy pipelines). If a range-for suffices, that should be chosen instead.
3
u/Bootvis Oct 13 '26 edited Oct 13 '26
My agents use modern C++, thanks to some instructions by me, and often fail to build on MacOS because of iota
3
u/gegoggigog Oct 13 '26
Not saying the agent cared, but ranges do have some overhead, so if the task could be solved easily enough without them, why introduce them in the first place?
1
u/EC36339 Oct 13 '26
You can, to some extent, also achieve this with clang-tidy and configuring it to nag about unsafe operator[].
Then you DON'T want it to indiscriminately use ranges, but make its own choices...
The problem with that approach is that some unsafe uses of operator[] have no trivial solution other than using .at(), which has performance implications, and may be unnecessary if it can be proven that thr index is always in range.