Open
Conversation
These functions act like std::get<T>(v), except that they do not throw if the current alternative is not T -- they (probably) just crash.
Contributor
|
If you're interested in something lighter-weight that is completely untested, I threw together a |
std::variant is part of C++17, right? So if a compiler claims it supports C++17 via the __cplusplus macro, then <variant> should be available and usable, right? Oh, you naive fool. Firstly, std::variant is indeed available in GCC/libstdc++ 7, but unfortunately its move constructor isn't constexpr. This is presumably a bug that was fixed in version 8. Furthermore, Apple flat-out lies about C++17 support. For AppleClang versions less then 10, the <variant> header simply doesn't exist; for version 10.0 (current at time of writing) the header exists and the symbols are there, but they're all deleted unless you're also compiling on the latest MacOS (v10.14, even though XCode 10 is also availabke for MacOS 10.13). I have no idea whether it's possble to detect the MacOS version via a macro or not. Finally, MSVC seems to be fine, presumably because we only actually support the latest version. Except in C++14 mode, where we use MPark.Variant, which gives apparently attempts to access the wrong union member in some constexpr code...
Owner
Author
|
Thanks Casey, I'll take a look. How many standard libraries are you implementing now?! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds Michael Park's variant implementation, and uses it in common_iterator (unless we're compiling with C++17, in which case std::variant is used).
This shrinks common_iterator a little, but at the cost of potentially worse codegen for various functions: in particular, operator==() gets routed through std::visit, which may not optimise all that well.
There's also the fact that MPark.Variant is absolutely huge -- at around 3kloc, it's about 20% the size of the whole of NanoRange at present. If it were just for common_iterator, I probably wouldn't bother; but we may be able to reuse it to implement
semiregular, and thus avoid having to drag in an equally-large optional implementation from somewhere.