3 ms·
In C++ std::optional<T>::value throws an std::bad_optional_access exception when the value is missing. How is this different from a NullPointerException?
by GoblinSlayer 4y ago
In C++ std::optional<T>::value throws an std::bad_optional_access exception when the value is missing. How is this different from a NullPointerException?
- lmm 4y ago> How is this different from a NullPointerException? It's different because most things can't throw it. The problem isn't that your language has a way to implement a value that might be absent, the problem is that your language does't have a way to implement a (heap) value that won't be absent, except by convention.
- GoblinSlayer 4y agoIf the value won't be absent, then it won't throw.
- lmm 4y agoI'd like to know that the value won't be absent when I build the code rather than when I execute it.