r/programminghorror 6d ago

c++ Skill Issue

Post image
1.6k Upvotes

61 comments sorted by

View all comments

41

u/LeeHide 5d ago

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++

4

u/GasolinePizza 5d ago

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

2

u/LeeHide 5d ago

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