-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Simplify <optional> macro #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hmm, I think the argument for keeping both is that they may be different types in an actual implementation of libstdc++. So partial overloading just on std::optional may break std::experimental::optional code. |
It still has both--they just get referenced via |
(And we don't ever support both at once). |
Yes -- but what if we're compiling code on a c++17 compilant compiler that was still using std::experimental::optional? |
(I admit that I don't really get the policies about std::experimental namespace. For instance, will aliases there always exist or only temporarily?) |
cc @aldanor |
But I think that we do want to support both at once, that was one of the points. GCC has both and the experimental one is not going away in GCC 6. Maybe next major GCC or may be not. If you look at your compiler's experimental include folder, you'll find a bunch of stuff there that has become stable since. |
At least for libstdc++, this is impossible: including I took a look at clang with libc++, and, at least as of llvm 3.9, the current |
Hmm, perhaps I'm wrong about it, but I'm pretty sure it was the case with the gcc-7 snapshot when I submitted the other PR, but I can't reproduce that now. With the current snapshot, including both seems fine--I'll amend the PR. And indeed they are not the same:
outputs: |
Never mind, I'm just misremembering the logic here; including both was always allowed. I'll fix the PR to just fix the test case. |
aca0b19
to
4c27e68
Compare
My bad on that one (especially considering I wrote that logic in the first place), sorry for the noise. I amended the PR to just add testing for std::optional when available. |
And though we don't currently have any tests in C++17 mode, I tested it locally with a g++ 6.2 with -std=c++17 and it runs and passes both tests. |
Thanks! |
This simplifies the std::optional/std::experimental::optional macros by
having just one macro that provides the namespace (either
std
orstd::experimental
), which removes some code duplication.It also enables the std::optional test which was previously only
testing optional under c++14 mode with std::e::o, but skipping it under
c++17 mode with std::o.