visit() should not pass prvalues to its callable
ned14 opened this issue · comments
Otherwise lvalue ref taking callables don't compile: https://godbolt.org/z/4j3efaP9W
@pdimov Asked me to submit this bug.
https://godbolt.org/z/5Pdd7nvbz doesn't work, one needs to do https://godbolt.org/z/8YocbodaG.
The workaround is to use auto&&
, but it would be more consistent for auto&
to work, as nullptr
is the only case that passes an rvalue.
I've written a fix, but then decided to also write a rvalue reference overload for visit, at which point I've reached a conundrum. We don't have rvalue ref-qualified overloads for e.g. get_bool
and get_double
, as there's no need for them. Due to that a visitor that has a bunch of operator(T&&)
overloads will not work. Which makes me rethink whether it's actually necessary to make visitor::operator()(nullptr_t&)
work. Maybe it is better to simply better explain the behaviour in documentation.
On the other hand, a visitor with operator(T)
overloads will work with rvalue ref-qualified overload, so maybe that's good enough?