Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In C++ std::optional<T> does the trick, as of version 11, and boost::optional<T> previously.

In C ... hrm you could probably wrangle some macros around that struct if you were desperate.



Nitpick: std::optional<T> does not exist in C++11, nor in the recently-approved C++14. It is, nevertheless, in the process of getting into the standard, and is already present in GCC 4.9's libstdc++ as std::experimental::optional.


Unfortunately `std::optional` did not get accepted for C++14, because it's implementation uses some hacks that are undefined behavior by the standard (but work on the major compilers).




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: