Closed pwrliang closed 3 years ago
Yes, this is by design. In case of success, a leaf::result<T>
contains a T
object, but in case of an error, by default, it does not contain error objects -- they get transported directly to the error handling scope.
If you need to collect results and then handle errors later, you need to make a leaf::polymorphic_context
, which can then be stored in a leaf::result
. This example is similar to your use case, except that the leaf::result
objects are computed asynchronously by worker threads: https://github.com/boostorg/leaf/blob/master/examples/capture_in_result.cpp.
Tutorial: https://boostorg.github.io/leaf/#tutorial-async_result.
Hi there,
I'd like to use std::vector to store a series of leaf::result, because both of a valid value or an error can be represent by leaf::result. Like,
std::vector<boost::leaf::result<int>> result_vector
.Assuming I have an error object
MyError
:I'm trying to push_back a normal value and an error object into the vector, then iterate the vector. I expect MyError object can be handled, but it hits the unmatched branch.
The output:
Thanks, Liang