4 ms·
It's not a great usecase for optionals. a better one would be retrieving a value from a std::map - that one is pretty binary, it's either there or it isn't. To
by HumanDrivenDev 9y ago
It's not a great usecase for optionals. a better one would be retrieving a value from a std::map - that one is pretty binary, it's either there or it isn't.
To me optionals are for things where you'd consider it reasonable to return a null that represents "doesn't exist".
- Shoothe 9y agoBut if you already have null then the method could return null, empty optional or optional with value.
- HumanDrivenDev 9y agoI don't know about C++, but for example Java has a method "ofNullable" that will convert a null to a None option. But yes, that could potentially happen. IIRC that problem exists in many languages, including F# and Scala. Not sure how big of an issue it is in practice...