Boost C++ Libraries: Ticket #6971: apply_visitor doesn't work with rvalue / const variants https://svn.boost.org/trac10/ticket/6971 <p> Hello, </p> <p> I noticed the <code>apply_visitor</code> 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? </p> <p> In case this is an omission, the fix seems to be trivial. The <code>apply_visitor</code> function seems to simply forward to the internal <code>apply_visitor</code> 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 <code>apply_visitor</code> function that takes the variant parameter by const reference and call it's <code>apply_visitor</code> member. Something like this: </p> <pre class="wiki">template&lt;typename Visitor, typename Visitable&gt; inline typename Visitor::result_type apply_visitor(Visitor&amp; visitor, const Visitable&amp; visitable) { return visitable.apply_visitor(visitor); } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6971 Trac 1.4.3 Antony Polukhin Sun, 05 Nov 2017 14:09:28 GMT owner, status, milestone changed https://svn.boost.org/trac10/ticket/6971#comment:1 https://svn.boost.org/trac10/ticket/6971#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">ebf</span> to <span class="trac-author">Antony Polukhin</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.66.0</span> </li> </ul> <p> Implemented by Levon Tarakchyan in <a class="ext-link" href="https://github.com/apolukhin/variant/commit/bdccd8d90e59563a371c82a6d4a0918521bdff96"><span class="icon">​</span>bdccd8d9</a> </p> Ticket Antony Polukhin Sun, 15 Apr 2018 16:57:23 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6971#comment:2 https://svn.boost.org/trac10/ticket/6971#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket