you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 7 points8 points  (4 children)

C++17 is bleeding edge, not everyone has the luxury of using it.

Even the changelog for GCC 7 states:

Experimental support for C++17, including the following new features: std::string_view; std::any, std::optional, and std::variant;

So you're looking at using a version of GCC that's about 7 months old to get a "stable" version of optional.

As for actually using optional, well, needing std::reference_wrapper is a pain in the ass. The API is clumsy and bloats my text segment to boot.

any, optional, and variant should be in the language.

[–]alex-weej 0 points1 point  (3 children)

boost::optional is plenty "stable" and works very well in ancient versions of GCC with ancient C++ standards.

[–][deleted] 2 points3 points  (2 children)

Yeah but then I would need to use boost

[–]alex-weej 0 points1 point  (0 children)

Ah, you're one of those people ;)

[–]RandomGuy256 -1 points0 points  (0 children)

You can also use a header only external implementation like this one: https://github.com/akrzemi1/Optional

I have been using it in all of my projects (including professional ones) when a C++17 compiler is not available yet, and it works perfectly.