Niall Douglas wrote:
See what you make of my toy std::variant<> based Outcome at:
FWIW, Niall, I convinced my variant implementation to work in Compiler Explorer:
so you can try it for a spin. It's never-valueless, ever, so you can dispense with the "safe assign" workarounds.
Here's a simplistic result<> based on that:
https://godbolt.org/g/EG6Kht
g++ 7.1 turns this:
#include <iostream>
result<int> function()
{
return 14;
}
int main()
{
std::cout << function().value() << std::endl;
}
into this:
function():
mov rax, rdi
mov DWORD PTR [rdi], 1
mov DWORD PTR [rdi+8], 14
ret
main:
sub rsp, 8
mov esi, 14
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream ::operator<<(int)
mov rdi, rax
call std::basic_ostream