r/cpp • u/claimred • Apr 09 '26
0xd34df00d/you-dont-know-cpp: and neither do I
https://github.com/0xd34df00d/you-dont-know-cppSome non trivial cpp quiz style questions
155
Upvotes
r/cpp • u/claimred • Apr 09 '26
Some non trivial cpp quiz style questions
53
u/ignorantpisswalker Apr 09 '26
I hate this.
I will re-read it again tomorrow.
35
u/WittyWithoutWorry Apr 09 '26
I hate how unreadable this language can get.
Thanks for the resource tho
27
u/jdehesa Apr 09 '26
I guess I'll have to add "
return <expression>;might produce a different result thanreturn (<expression>);" to my list of C++ fears.46
u/UnicycleBloke Apr 09 '26
It reads like a pub quiz of obscurantism in C++. I generally try to avoid code which relies on arcane knowledge. Doesn't everyone?
17
u/viatorus Apr 09 '26
I had a good laugh seeing my 7 years old comment under the linked "GCC Bug", which still isn't fixed. Thank you for making my cry.
11
u/Nicksaurus Apr 09 '26
🥲
5
u/Morwenn Apr 09 '26
Oh man, and there I thought that the variable template ODR issue was fully solved by CWG2433.
9
u/ReDucTor Game Developer | quiz.cpp-perf.com Apr 09 '26
Not knowing everything edge cases included does not mean you dont know something. These gotcha/trivia things are fun but it doesnt prove anyone a better or worse programmer.Â
8
u/TheThiefMaster C++latest fanatic (and game dev) Apr 09 '26 edited Apr 09 '26
Well that's just mean when it involves a new C++26 feature.
What do you mean by this? What does it not type check? Do you mean "you get errors in the return type of foo"?
4
u/da_supreme_patriarch Apr 09 '26
I hate the one with virtual functions' return types' constness so much, that made me unreasonably angry
4
u/triconsonantal Apr 09 '26
In the one with the map, you can use the unhelpfully-named
try_emplace()to simplify the insertion quite a bit.4
u/onafoggynight Apr 09 '26
That's a great reference of things that mostly shouldn't be allowed in codebases, and never pass review. Perfect.
4
u/tcbrindle Flux Apr 09 '26
For the "requires-constrained return types" question, if you're absolutely determined not to use
autoreturns then I don't think this is too bad as a workaround: https://godbolt.org/z/WEceMzh4h4
u/tcbrindle Flux Apr 09 '26
In the first question, the use of a C++26 structured binding pack is a bit of a red herring. Taking the
decltypeof a structured binding member has worked that way since they were introduced in C++17: https://godbolt.org/z/vnazEMYqa.3
u/Orlha Apr 09 '26
Oh I love things like this! Thanks
3
u/heyheyhey27 Apr 09 '26
I don't know C++
3
u/mcmcc #pragma once Apr 09 '26
I've been hit multiple times by the nested class initialization problem. It's obnoxious.
2
u/NuKe170 Apr 09 '26
Interesting. That's stuff not many people do/see/understand
2
u/germandiago Apr 09 '26
Some puzzling puzzles around.
2
u/wiesemensch Apr 09 '26
As someone who mainly works in C#, I don’t want to see any of this in a project. It relies way too much on developer knowledge.
4
u/float34 Apr 09 '26
Might be a good self-check list for anyone learning the language, thanks.
2
u/PipingSnail Apr 09 '26
I've been writing C since 1990 and C++ since 1994. Before that, 6 years of assembler.
Amazing how you can take a productive language like C++ and turn it into a byzantine pile of complexity for no good reason.
If I found someone writing such obscure code I'd have word with them about writing maintainable code, and then get them to write something more understandable.
That's how you end up with multi million line code bases and have readable, maintainable code with very low bug counts. Keep out the code from people trying too hard to be clever without a thought for the people that have to work on it afterwards.
I'm glad I read that, our decision not to chase the bleeding edge of C++ language standards has been vindicated.
1
u/Business_Welcome_870 Apr 09 '26
InterestingÂ
1
u/13steinj Apr 09 '26
After doing all of this, it proves I need to get out more.
I prefer "do" XYZ thing type questions though, as they serve a practical purpose.
1
u/CornedBee Apr 10 '26
Regarding specialization fun, another way this will bite you:
IsSimpleContainer<std::vector<int, my_own_allocator<int>>>is Undefined.1
u/Orkiin Apr 11 '26
Thanks for reminding me to stay in C
1
u/Bubbly_Rain7858 Apr 10 '26
"C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, it blows your whole leg off." -Bjarne Stroustrup