In C++23, monadic operations in std::optional
was adopted, and later on std::expected
. Why were monadic operations like and_then
, transform
, and or_else
not included in the main paper?

- 1,517
- 1
- 7
- 19
-
1I think they cover that in §11.2 of the latest proposal. – vandench Feb 09 '22 at 01:05
-
Was `expected` adopted for C++23? – Nicol Bolas Feb 09 '22 at 02:22
-
3@NicolBolas Yes, as of yesterday. – Barry Feb 09 '22 at 06:05
-
Meanwhile does exists an implementation with monadic enabled: https://github.com/TartanLlama/expected – Moia Aug 24 '22 at 12:34
1 Answers
Update: std::expected
in C++23 will have monadic operations.
The std::expected
proposal is very old. The adopted revision is P0323R12, which already suggests a long life, but that paper even predates the P-numbering system and started out as N4015, dated May 2014.
I bring this up because std::expected
, even by itself, has taken a very long time to wind its way through the process. In contrast, the monadic operations for std::optional
paper only first appeared in October 2017. And since then it was just a long slog just to get std::expected
at all.
There is a paper proposing monadic operations for std::expected
, that's P2505R0, but at this point it's very incomplete and needs a lot of work. The design window for new C++23 features is closed, but I wouldn't be surprised if there were an NB comment requesting it in later anyway.
At least we finally have std::expected
.
Coming in here a few months later, there was an NB comment requesting the monadic operators for std::expected
and P2505R5 was adopted for C++23 in Kona in November 2022.

- 286,269
- 29
- 621
- 977
-
1For what it's worth, [P2505 seems to be on-track for C++23](https://github.com/cplusplus/papers/issues/1161). At the very least, LWG seems to be open to considering it for C++23. – Nicol Bolas Sep 25 '22 at 22:28
-
It looks like there's no `.transform_error`. That seems desirable. Or does `.or_else` handle that? – Ben Jan 26 '23 at 22:57
-
1@Ben There is a `transform_error` now. Like I said, R0 of that paper was very incomplete. – Barry Jan 27 '23 at 02:26