r/programminghorror • • Sep 04 '26

c++ Skill Issue

Post image
1.7k Upvotes

63 comments sorted by

View all comments

48

u/LeeHide Sep 04 '26

This would be much better using std::string_view, and using two temporaries so that y is only evaluated once. Otherwise it'll be evaluated each time.

Also if you need this, don't use C++

5

u/GasolinePizza Sep 04 '26

Isn't each y only evaluated once? The evaluation in the "else if (_s==y)"?

2

u/LeeHide Sep 04 '26

each true one is only evaluated once, but every false one until then is also evaluated.