3 ms·
> You can have options and results in C++ if you like (I sometimes use custom result types, and I certainly don't use exceptions) It's not really practical bec
by lmm 7y ago
> You can have options and results in C++ if you like (I sometimes use custom result types, and I certainly don't use exceptions)
It's not really practical because C++ has no true sum types. You can emulate them with a Java-style visitor pattern but that carries an immense code overhead.
- lenkite 7y agoYou have std::variant and std::visit. https://www.bfilipek.com/2018/09/visit-variants.html https://www.bfilipek.com/2018/09/visit-variants.html Or you can use a library: https://github.com/mpark/patterns https://github.com/mpark/patterns
- lmm 7y ago> You have std::variant and std::visit. https://www.bfilipek.com/2018/09/visit-variants.html https://www.bfilipek.com/2018/09/visit-variants.html Which isn't a true sum type because it doesn't nest properly. > Or you can use a library: https://github.com/mpark/patterns https://github.com/mpark/patterns Interesting; proper pattern-matching is nice, but the lack of type safety is still a major issue.