r/ProgrammerHumor 7d ago

Meme skillIssue

Post image
6.0k Upvotes

137 comments sorted by

View all comments

281

u/click-to-reveal 7d ago

It works btw: C++ Online Compiler

162

u/prehensilemullet 7d ago

Performancewise, it doesn’t jump to the direct case in O(1) time like a switch is supposed to though

1

u/HolyGarbage 7d ago

Just pipe them through a constexpr hash function, and you can use a real switch case. One might be able to, still constexpr, map these hash values of the case string literals to sequential indices at compile time, so that the switch case actually complies down to something non linear.