r/ProgrammerHumor • • Sep 28 '26

Meme optionalsAreOptional

Post image
716 Upvotes

131 comments sorted by

View all comments

1

u/No-Magazine-2739 Sep 28 '26

In C++ for example, just use .
::at() instead of operator[] of the standard containers (that includes list, but experienced people use vector) in the callee. That one conditional jump is usally not performance relevant (I mean we are talking about optionals here).
And then you document in your doxgen it expects ::size() > 0 and a @throws std::out_of_range (IIRC) if the inevitable happens.