3 ms·
No, because in C++ bare types are not nullable. In java, reference types are nullable, Optional being a reference type, Optional<T> can be null, Empty, or have
by masklinn 4y ago
No, because in C++ bare types are not nullable. In java, reference types are nullable, Optional being a reference type, Optional<T> can be null, Empty, or have a value, whereas T can be null or have a value.
Also because std::optional does essentially the opposite. It’s a more efficient _ptr rather than a safer one. Optional<T> is strictly less efficient as it implies an additional allocation.
- krzyk 4y agoOK, so when valhalla lands I assume Optional will become value type (or we will have another class for that, to avoid issues with backward compatibility)
- dheera 4y ago> Optional<T> can be null, Empty, or have a value, whereas T can be null or have a value Thanks for the explanation. Wow, this sounds like a a bit of a mess, one because of the allocation, and also because it seems there are multiple ways something can be semantically null.