Boost logo

Boost :

From: Szalacsi Sandor (szalacsi_at_[hidden])
Date: 2005-02-02 18:59:52


Hello,

I tried to post this one to the boost.users newsgroup, but I did not
succeed:

"
Hello,

According to the docs and the source, boost::apply_visitor has two
overloads now:
template<typename Visitor, typename Variant>
   typename Visitor::result_type
   apply_visitor(Visitor & visitor, Variant & operand);
template<typename Visitor, typename Variant>
   typename Visitor::result_type
   apply_visitor(const Visitor & visitor, Variant & operand);

None of them is capable of taking a Variant instance by const reference,
only by reference.

One can certainly find workarounds for it, but that is not very simple,
see for example an attempt trying to remove constness using const_cast:
typedef boost::variant<int, std::string> MyVariant;
boost::apply_visitor(MyVisitor(), const_cast<MyVariant&>(MyVariant());
This does not work either due to rvalue/lvalue issues.
One can write some wrapper functions of course, but it is inconvenient.

My questions are: is this the product of intentional design? If it is,
what are the reasons for not allowing to pass variant by const
references? If it is not, what should be the most elegant way to visit
variants through const references?

Sincerely

Sandor Szalacsi

"

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.4 - Release Date: 2005.02.01.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk