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
Add a std::optional and std::variant implementation #5388
Conversation
Should this file be modified or be compliant with our coding style? If so, should we keep these Otherwise, it isn't used anywhere so I don't think it can harm, for the moment. |
That's pretty easy to change, so there you go. Fixed. |
Source/Core/Common/StdOptional.h
Outdated
} | ||
|
||
optional& operator=(optional&& rhs) noexcept( | ||
is_nothrow_move_assignable<T>::value&& is_nothrow_move_constructible<T>::value) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/Common/StdOptional.h
Outdated
|
||
// 20.5.4.4, Swap | ||
void swap(optional<T>& rhs) noexcept( | ||
is_nothrow_move_constructible<T>::value&& noexcept(swap(declval<T&>(), declval<T&>()))) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Have you considered calling the file just "optional" and use |
I'm not really familiar with the process of "backporting" newer C++ stuff, so I just followed #351. Is there any reason for using |
It's not standard anyway to provide anything in the As for MSVC, it does have it from 2017. We could up the requirement. And there might be a way to conditionally add the include path in vcxproj files. Another way to do it is to do it is to test if the header exists from CMake. If it does, then we use it, or we add an include path that makes this version available. Basically, I like compatibility headers to be transparent and with the same name :) |
Oh, all of that are suggestions that I think are worth exploring, not requirements in any way. |
How else would you use soon-to-be- We've done it before, it worked; but we mostly didn't have other alternatives available. I'm for exploring the alternatives and using standard headers if we can. |
IMO, I think updating to VS2017 would be nice. |
Is this preferable to using STX Headers? |
This is pretty much the implementation used in that repo. Since the move to VS2017 doesn't seem to be happening soon (because of buildbot stuff), how should we proceed with this PR? |
Okay, so we have now moved to VS2017, but I'm not sure about using
And to be honest, I don't see the benefit over a regular include. Whenever we want to use the upstream version, we would want to remove this implementation and replace the |
You're supposed to use the |
VS 2017 supports |
@Orphis It's been a while since I opened the PR, so I kind of forgot that we already use the upstream version where possible ( |
8c4bda0
to
acc56d1
Compare
Well, I like compatibility changes to be non intrusive for the users. So 2 options:
Is that clear enough now? :) |
6db5a12
to
7c369a5
Compare
@Orphis okay, I think I got it now. Would you mind reviewing this? |
Source/VSProps/Base.props
Outdated
@@ -80,6 +80,8 @@ | |||
<RuntimeTypeInfo>false</RuntimeTypeInfo> | |||
<MinimalRebuild>false</MinimalRebuild> | |||
<MultiProcessorCompilation>true</MultiProcessorCompilation> | |||
<!--Enable latest C++ standard--> | |||
<LanguageStandard>stdcpplatest</LanguageStandard> |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Looks fine. Let's wait for #5484 first I think! |
eccb5eb
to
d733ef7
Compare
CMakeLists.txt
Outdated
@@ -540,6 +540,13 @@ if(ANDROID) | |||
include_directories(Source/Android) | |||
endif() | |||
|
|||
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/CMakeLists.txt
Outdated
else() | ||
# Enable C++17, but fall back to C++14 if it isn't available. | ||
# This would have been simpler if cmake supported CMAKE_CXX_STANDARD = 17; | ||
# it currently doesn't, so this check has to be done manually. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
e33c4d1
to
e254887
Compare
std::optional makes a few things a bit neater and less error prone. However, we still cannot use C++17 (unfortunately), so this commit adds an implementation of std::optional that we can use right now. Based on https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/lib/gtl/optional.h which seems to be fairly similar to C++17's <optional> and standards compliant. It's one of the few implementations that handle propagating type traits like copy constructibility, just like libc++/libstdc++.
The whole NANDContentLoader stuff is truly awful and will be removed as soon as possible. For now, this fixes a bug that was exposed by std::optional::operator*.
Based on https://github.com/mpark/variant (which is based on libc++).
This broke compiling DolphinQt2 with CMake, for the reasons outlined in https://gitlab.kitware.com/cmake/cmake/issues/16468 |
std::optional makes a few things a bit neater and less error prone. However, we still cannot use C++17 (unfortunately), so this commit adds an implementation of std::optional that we can use right now.
To do:
std::optional<std::unique_ptr>
is considered to be copy constructible, when it really isn't...