As I am working on a C++ library that will be released publicly around 2014, I currently have design choices to make. One of the very useful tool that will be released with C++14 is std::optional
. I would like to know with what version of g++/libstdc++
I can expect to have it using -std=c++1y
.
C++17 Support in GCCC++17 features are available since GCC 5. This mode is the default in GCC 11; it can be explicitly selected with the -std=c++17 command-line flag, or -std=gnu++17 to enable GNU extensions as well.
Status of Experimental C++11 Support in GCC 4.8GCC provides experimental support for the 2011 ISO C++ standard. This support can be enabled with the -std=c++11 or -std=gnu++11 compiler options; the former disables GNU extensions.
The class template std::optional manages an optional contained value, i.e. a value that may or may not be present. A common use case for optional is the return value of a function that may fail.
Update (Oct 2016): std::optional
was not in the final C++14 standard, so it is never available with -std=c++1y
. Instead GCC 4.9 includes std::experimental::optional
which is avilable with -std=c++1y
.
GCC 7 will include std::optional
with -std=c++1z
i.e. C++17.
Original answer (Jun 2013):
It's currently unimplemented, see http://gcc.gnu.org/ml/libstdc++/2013-06/msg00032.html for the status of C++14 features in GCC's trunk.
When it gets implemented depends on when someone volunteers to do the work, so is impossible to predict.
I would expect it will be done for GCC 4.9, which should be released shortly before the C++14 standard, but there are no guarantees. It is unlikely to get added to GCC 4.8 though, as that's already released and unlike GCC 4.9 (i.e. the GCC subversion trunk) the __cplusplus
macro has the same value for -std=c++11
and -std=c++1y
so for GCC 4.8 there's no way to selectively enable features for -std=c++1y
only.
As per their libstdc++ status page GCC 7.1 is the first version to have std::optional
without being hidden in std::experimental
and it supports the __has_include(<optional>)
feature test. The feature test __cpp_lib_optional >= 201603
was added in GCC 7.3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With