C++23 adds some "monadic-style" functionality regarding optionals, as methods of optional<T>:
optional<T>::and_then() (and ignoring qualifiers of this):
template<class F> constexpr auto and_then(F&& f);Returns the result of invocation of f on the contained value if it exists. Otherwise, returns an empty value of the return type.
optional<T>::transform() (and ignoring qualifiers of this):
template<class F> constexpr auto transform(F&& f);Returns an
std::optionalthat contains the result of invocation offon the contained value if*thiscontains a value. Otherwise, returns an emptystd::optionalof such type.
So, aren't these two functions doing the same thing?