7 ms·
It seems a bit like the difference between async fn foo() -> int and fn foo() -> Async<int> (pseudo-rust syntax but the distinction also applies to
by mastax 8y ago
It seems a bit like the difference between
async fn foo() -> int
and
fn foo() -> Async<int>
(pseudo-rust syntax but the distinction also applies to C# and JS, et. al.)
Async code and error handing can both be implented with regular code, but there are cases where some compiler magic can be more elegant, more expressive, or more performant. In these cases it's nice to have a construct that distinguishes this magic from regular values, rather than just making a specific return type magic, IMO. In the throwing values proposal, the magic is to make a regular value usable in exceptions, and also to use mostly-hidden CPU state (flags register) to indicate the type of the value. This allows the C++ proposal to use less memory and perhaps be more performant than rust-style error values. (This ABI change could also be used in other languages like Rust, as mentioned at the end of the document)