-
Notifications
You must be signed in to change notification settings - Fork 27
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
Argument to nonstd::visit is always a const reference? #42
Comments
Yes, the overview page explicitly lists all arguments to The reason your tests work for C++17 is because when using C++17 |
What limitation in pre-C++17 stops visit from taking the arguments as non-const lvalue references? |
I'm not really qualified to answer this, since I didn't take a good look at how visit is implemented here. But my guess is that the code currently implements visit using const lvalue ref, since that makes it compatible with C++98. With a couple of extra |
Oh, I suppose even with C++11, using just plain lvalue references would prevent you from using visit with temporaries, since temporaries can't be passed as a non-const reference... I suppose you have to use universal references to get it to work right. |
I imagine I'm having the same problem, but the following doesn't work for C++ < 17:
For C++ >= 17, it's fine. @martinmoene Is this the desired behaviour? |
If someone wants to write a PR at some point, abseil has an implementation too for reference. |
@pfeatherstone, Making At the moment I'm quite removed from the internal workings of
|
Cheers |
Try as I might, I cannot use
nonstd::visit
on C++14 to mutate the item currently stored in a variant. If I change to-std=c++17
(and therefore usestd::variant
), it works.Very simple example: https://godbolt.org/z/nsYqxs
The text was updated successfully, but these errors were encountered: