Opened 6 years ago

Closed 4 months ago

#6971 closed Bugs (fixed)

apply_visitor doesn't work with rvalue / const variants

Reported by: adam.ciganek@… Owned by: Antony Polukhin
Milestone: Boost 1.66.0 Component: variant
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc:



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 Changed 10 months ago by Antony Polukhin

Milestone: To Be DeterminedBoost 1.66.0
Owner: changed from ebf to Antony Polukhin
Status: newassigned

Implemented by Levon Tarakchyan in bdccd8d9

comment:2 Changed 4 months ago by Antony Polukhin

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.