Hi, I believe that this private mail I sent to Niall could concern the Boost community and the Outcome review. While the post concerns the proposed std::experimental::expected, this is applicable as well to Outcome. I've added a more points at the end and some additional information about possible open points for std expected. Le 24/05/2017 à 01:04, Vicente J. Botet Escriba a écrit :
Hi,
After better understanding of the goals of Boost.Outcome I would like to share two possible extension of std::experimental::expected
1. Implicit conversion when the errors are convertible and the type is the same.
I believe this is a missing constructor.
EXPLICIT expected
::expected(expected ); // E is convertible from G I see that the other constructor is also useful
EXPLICIT expected
::expected(expected); // T is convertible from U and so
EXPLICIT expected
::expected(expected); // T is convertible from U and E is convertible from G
We could as well have an adapt function that transforms expected error
explicitly to do error propagation
adapt : (E->G) x expected
2. variadic expected
I suggested this already in revision 2 of the Expected standard proposal.
expected
should be something like variant but with some syntactic sugar. expected
could be EXPLICIT convertible from expected as far as for all Gj we find a unique Ek that is convertible to.
We can refine the subsumption relation this could take too long to the compiler (as the previous relation has quadratic complexity as Andrzej reported to me).
I believe this will cover exactly what outcome covers and in addition it will let open the error types used by the user.
It acts as a exception specification, which we have abandoned in C++11.
expected
f(); T f() throw (E1, ...., En);
We can consider that this is bad, as we have abandoned it.
Anyway, I think that expected
is a good generalization of the proposed outcome<T> where E1 could be none_t, E2 could be error_code and E3 is exception_ptr.
At the end users could use variant
In this way we could have
template <class T>
using option = expected
; Note that this is different to std::optional as the default is T not nullopt_t :(
I'm not proposing it. Just to say that this could be a possibility for option.
template <class T>
using result = expected
; // and possibly none. template <class T>
using outcome = expected
; I believe we would need the syntactic sugar as expected
> should have a lot of user code noise.
In addition it will be less efficient than variant
E.g. expected
> should be convertible from unexpected_type<G> as soon a one of the Ek is convertible from G. I believe variant
is not convertible from variant under the conditions described above, but maybe this should be the case.
Andrzej told to me that this is already the case for optional<T>, but I've not found yet on which paper this was added?
Of course, the never empty warranties could be supported only if the types Ek allow it and we need to change the standard to ensure it for exception_ptr.
I will not have time to implement a POC for 2, but I believe I could do it for 1 before Toronto. Anyway I believe it will be worth discussing these 2 extensions.
Best,
Vicente
P.S. EXPLICIT above has the sense given in the standard.
3. uninitialized default constructed expected