Using optional before C++17


We have a codebase that’s built with C++14 and was using <experimental/optional> to use std::optional. This no longer works with libc++ 7 onwards, since <experimental/optional> was removed per the TS deprecation policy.

We can’t use because that’s limited to C++17 and above. We’re working on upgrading our codebase, but it’ll take time :slight_smile: I’m wondering if there’s any solution available that’ll work pre-C++17. Our current plan was to overlay our own <experimental/optional> that’s a copy of the one from libc++ 6, but some sort of solution in the library itself would be ideal.

I recall there being some past discussion about this, but I can’t find it right now. Looking forward to any suggestions here.



Unfortunately, I don't know of any other solution. In retrospect, we should have added a deprecation warning to experimental::optional one year before removing it so as to give a heads up to people. However, now that it has been removed, there isn't a workaround. I've suggested to other people that they use boost::optional pre-c++17, but that is obviously not an optimal solution.