3 ms·
> the incorrect way for either performance (anything newly added like std::variant or std::optional) or safety I don't know where you got that idea from, but w
by logicchains 4y ago
> the incorrect way for either performance (anything newly added like std::variant or std::optional) or safety
I don't know where you got that idea from, but with an up-to-date compiler variants are safer and more performant than the traditional approach (classes hierarchies), and std::optional is safer and 99.9% as performant as a nullable pointer.
- ben-schaaf 4y ago> and std::optional is safer and 99.9% as performant as a nullable pointer. Except for it taking up twice the memory as a pointer (https://godbolt.org/z/5We9zEbvh https://godbolt.org/z/5We9zEbvh) and it not doing anything in regards to safety when using pointers. Even if you're replacing a nullable-pointer with a std::optional you're still handling landmines when using operator* or operator-> - the most convenient ways to use std::optional.
- pornel 4y agoThe fact that modern C++ still added more easy to hit UB in std::optional blows my mind. "But making it safe would be slow!" and "-> being safe would be inconsistent with the rest of the language". C++ is doomed forever to have safety-third design.