lefticus / cpp_weekly

The official C++ Weekly Repository. Code samples and notes of future / past episodes will land here at various times. PR's will be accepted in some cases.
The Unlicense
668 stars 24 forks source link

Exceptions for better performance #158

Open lefticus opened 1 year ago

lefticus commented 1 year ago

A comparison of the monadic call chain interface from std::optional in C++23 and using exceptions to handle error cases instead.

usefulcat commented 1 year ago

I would upvote this 10x if I could. I have long theorized, but never had the chance/taken the time to prove, that using exceptions to report uncommon conditions can be measurably faster than manually checking and propagating error return values, especially with a deep-ish call stack.

fcolecumberri commented 1 year ago

could you add std::expected to the comparison?

lefticus commented 1 year ago

could you add std::expected to the comparison?

Good idea. I've observed that it's shockingly easy to use std::expected inefficiently.

cough implicit conversions cough