3 ms·
The vastly more common use-case I've seen is when you want to have an optional value, but don't want the heap allocation that comes with std::unique_ptr. std::
by Matheus28 8y ago
The vastly more common use-case I've seen is when you want to have an optional value, but don't want the heap allocation that comes with std::unique_ptr.
std::optional is an useful wrapper because a simple "bool + object" would call constructors and all when that might be undesirable.
IMO, ternary logic belongs as an enum class, to require developers to be explicit about what branches are taken for what values.
- Koshkin 8y agoheap allocation that comes with std::unique_ptr I think it may be worth mentioning that std::unique_ptr can be used to "manage" non-heap pointers as well.