3 ms·
> anything that adds a branch to check dereference in release builds is an instant no-go ...which, as shown by Rust, is actually not true, and is very much a g
by kouteiheika 4y ago
> anything that adds a branch to check dereference in release builds is an instant no-go
...which, as shown by Rust, is actually not true, and is very much a go in the vast majority of cases.
> what do you propose to do instead?
It's easier and more natural to access the optional in an unsafe way (through the -> operator) than access it in the safe way (through `value()`); this is a wrong default which should have been made the other way around.
Potentially unsafe behavior should be opt-in, instead of opt-out. Yes, it's important that you have the option to disable this check for performance-sensitive code. But the majority of the code is not performance-sensitive to this degree that an extra branch is going to make any difference whatsoever.
- kllrnohj 4y ago> It's easier and more natural to access the optional in an unsafe way (through the -> operator) than access it in the safe way (through `value()`); this is a wrong default which should have been made the other way around. Then it's inconsistent with std::vector & similar. Consistency across the standard library seems much more worthwhile, especially here where it's pretty obvious when you mess up using a std::optional (like just never checking if it has a value, which jumps out in code reviews quite clearly)