Hacker News new | past | comments | ask | show | jobs | submit login

> 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) 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.




The 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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: