Opened 10 years ago
Closed 5 years ago
#6971 closed Bugs (fixed)
apply_visitor doesn't work with rvalue / const variants
Reported by: | Owned by: | Antony Polukhin | |
---|---|---|---|
Milestone: | Boost 1.66.0 | Component: | variant |
Version: | Boost 1.49.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Hello,
I noticed the apply_visitor
function doesn't work when the passed in variant is const or rvalue. This is because there is no overload accepting the variant via const reference. Is this deliberate, or is it an omission?
In case this is an omission, the fix seems to be trivial. The apply_visitor
function seems to simply forward to the internal apply_visitor
member function of the variant type. There is already a const version of this member function in the boost::variant sources, so all that is needed is to add new free apply_visitor
function that takes the variant parameter by const reference and call it's apply_visitor
member. Something like this:
template<typename Visitor, typename Visitable> inline typename Visitor::result_type apply_visitor(Visitor& visitor, const Visitable& visitable) { return visitable.apply_visitor(visitor); }
Change History (2)
comment:1 by , 5 years ago
Milestone: | To Be Determined → Boost 1.66.0 |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Implemented by Levon Tarakchyan in bdccd8d9