[llvm] [libc] Add monadic functions to cpp::expected (PR #66523)

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 01:18:46 PDT 2023


gchatelet wrote:

> Is there a use case for adding this? This is a rather large rewrite of `expected` unless there is a followup planned.

Yes absolutely there is a use case. A more modular approach to number parsing (POC https://godbolt.org/z/zssrGdffG).
This would allow us to compose parsers and support different use cases like `char` vs `wchar`, `FILE*` vs C string, and the difference in error reporting. It also makes them more testable as each piece can be tested individually,

Now, TBH I didn't think implementing the monadic interface for `expected` would require that amount of work so I totally understand the push back (or at least the question about its usefulness). That said I think the monadic approach is valuable (testability, composability) for code that needs to deal with error propagation.

https://github.com/llvm/llvm-project/pull/66523


More information about the llvm-commits mailing list