• porgamrer@programming.dev
    link
    fedilink
    arrow-up
    4
    ·
    2 years ago

    I tried coming up with a decent Result type and Try macro in C++ and got nowhere. To be usable I need something like this:

    auto value = Try(expression);

    Where the Try expression will either return the error type immediately or evaluate to the success type.

    As far as I can tell there’s no portable way to implement that macro in C++20, and nothing coming down the pipe either. I don’t think chaining lambdas is good enough. It can make the code uglier than just manually checking returns.

    I’ll be happy if anyone can correct me though.

      • porgamrer@programming.dev
        link
        fedilink
        arrow-up
        3
        ·
        2 years ago

        Yeah, I came across that. I presume it just uses the GCC statement expressions extension under the hood.

        No can do though, it has to work with MSVC too.