Opened 6 years ago

Last modified 6 weeks ago

#6971 assigned Bugs

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);

Attachments (0)

Change History (1)

comment:1 Changed 6 weeks 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

Modify Ticket

Change Properties
Set your email in Preferences
as assigned The owner will remain Antony Polukhin.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.