Hacker News new | ask | show | jobs
by 0xmaverick 2935 days ago
I find this useful for older paradigms where you want an error as well as pass in something to fill in as the output. Instead of doing bool foo(OutFoo* out_foo) or overloading Id getId(); // returns -1 if not present. You could use base::Optional<OutFoo> / base::Optional<Id> in each case respectively.
1 comments

You may find std::variant also very useful. You can do something like std::variant<Error, Foo>.