-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Use custom definitions for negation and bool_constant #737
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
Instead of relying on sometimes missing C++17 definitions
include/pybind11/common.h
Outdated
#if defined(PYBIND11_CPP17) || defined(_MSC_VER) | ||
using std::bool_constant; | ||
using std::negation; | ||
#else | ||
template <bool B> using bool_constant = std::integral_constant<bool, B>; | ||
template <class T> using negation = bool_constant<!T::value>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this line with the following to fix the MSVC internal compiler error:
template <typename T> struct negation : bool_constant<!T::value> { };
The other compilers can get away with just the alias, but I don't think it's worth splitting up the implementation over it.
In general, I'm a little hesitant to bother worrying about significantly incomplete C++17 support in compilers (or the associated stl, in this case); we're talking about experimental support for a not-yet-released C++ standard. In this case, the workaround is pretty simple (and actually slightly reduces code), so it seems acceptable; but there's a reason we do the C++17 travis-ci testing on a gcc/stdlibc++ 7 snapshot and clang/libc++ 4.0 release: those are the first to support a reasonable set of C++17 features. (I believe AppleClang/libc++ is based on LLVM 3.9). So I guess what I'm saying is: "doesn't work in unreleased standard mode on a non-cutting edge compiler" really doesn't seem an appropriate PR justification for anything more than a trivial change. |
@jagerman I agree completely. |
I still think that the right way for this is to rely on feature-test macros (here's a list) : it does not add much code and you can be certain that what you want to use is there. |
Unfortunately MSVC doesn't support them, so it would still need the MSVC version checks, but yes, I agree that that's a better approach. Regarding this PR: part of the reason I like the |
As such I think I'd prefer this PR if, instead of removing the "using", it replaced the condition with #if defined(__cpp_lib_logical_traits) || defined(_MSC_VER) (Then you also don't need the MSVC struct fix). |
(Or you could accomplish the same with a simple comment to that effect; I'll let others weigh in). |
I thought removing the condition would simplify things since the I will say the SD-6 feature-test macros look great and I wasn't aware that they were semi-standardized. I'm definitely in favor of using them for C++17 features going forward since it looks like GCC, clang and Intel/EDG support them. |
Merged, thanks @jcelerier! |
thanks to you ! we can finally get back to work :p |
Instead of relying on sometimes missing C++17 definitions
As requested per PR#735