ned14 / status-code

Proposed SG14 status_code for the C++ standard
Other
66 stars 13 forks source link

How to clone a status_result<void>? #42

Closed Tradias closed 2 years ago

Tradias commented 2 years ago

Since Boost 1.79.0 I am struggling to clone a status_result<void> as the following code stopped compiling:

https://godbolt.org/z/Pezhxnrq8

#include <boost/outcome/experimental/status_result.hpp>
#include <optional>

namespace outcome = BOOST_OUTCOME_V2_NAMESPACE::experimental;

template <class T>
using Result = outcome::status_result<T>;

void b(std::optional<Result<void>>& result) {
    result.emplace(outcome::success());
}

And as a more general question: How to clone a status_result<void>? I was using a function like this so far:

    Result<void> clone_result(Result<void> result)
    {
        if (!result)
        {
            return std::move(result).assume_error().clone();
        }
        return outcome::success();
    }
ned14 commented 2 years ago

Should be fixed in current trunk?

You're right the Boost 1.79 release is broken. I did post a patch to the mailing list.

ned14 commented 2 years ago

And as a more general question: How to clone a status_result? I was using a function like this so far:

There are clone() free functions in trunk Outcome for basic results and basic outcomes with status codes in them.

Tradias commented 2 years ago

Cool that works, thank you!