Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std optional: No such file or directory

I tried to compile the following program with different compilers (including gcc 6.1) :

#include <optional>
int main()
{
    std::optional<int> o1;
}

Output is

main.cpp:1:20: fatal error: optional: No such file or directory #include optional

This is even true for the examples given here: http://en.cppreference.com/w/cpp/utility/optional/optional

Any clues why?

like image 876
scoulomb Avatar asked Jul 07 '16 19:07

scoulomb


1 Answers

std::optional will be part of the C++17 standard, but if you want to use before then you will have to use std::experimental::optional instead, available in the header <experimental/optional>.

like image 117
SirGuy Avatar answered Sep 21 '22 12:09

SirGuy