simontoth,
@simontoth@hachyderm.io avatar

The C++23 standard introduced a monadic interface for std::optional<T>.

  • transform(f(T)->U)->std::optional<U>

only invoked when the source isn't empty

  • and_then(f(T)->std::optional<U>)->std::optional<U>

only invoked when the source isn't empty

  • or_else(f()->std::optional<T>)->std::optional<T>

only invoked when the source is empty

Compiler Explorer link: https://compiler-explorer.com/z/4dzc776Gq

#cpp #cplusplus #coding #programming #dailybiteofcpp

  • All
  • Subscribed
  • Moderated
  • Favorites
  • cpp
  • DreamBathrooms
  • ngwrru68w68
  • modclub
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • mdbf
  • ethstaker
  • megavids
  • osvaldo12
  • tester
  • GTA5RPClips
  • cubers
  • everett
  • tacticalgear
  • cisconetworking
  • normalnudes
  • anitta
  • provamag3
  • Leos
  • JUstTest
  • lostlight
  • All magazines