Boost logo

Boost :

From: Theodore Omtzigt (tomtzigt_at_[hidden])
Date: 2006-09-04 19:55:17


Dear Boost list Gurus:


I got stuck trying to write a binary visitation of a Boost.Variant that
modifies one of the arguments, like so:


typedef boost::variant<int, float> myVariant;


class add : public boost::static_visitor<> {


      void operator()(myVariant& lhs, const myVariant& rhs)const {

            lhs += rhs;




This won't compile with an error indicated that the lhs reference that is
not to 'const' cannot be bound to a non-lvalue. I don't understand this
error message and the many function template instantiations that are given
as reference for the compilation error. Furthermore, I haven't gotten any
new ideas how to fix this in the past 2 hours, so I hope to turn to this
list for possible solutions. How does one write a binary visitor for
Boost.Variants that allow modification of its arguments? Or if that is not
possible, how does one, generically, compute with boost::variants?


Looking forward to comments that help me understand this,




Boost list run by bdawes at, gregod at, cpdaniel at, john at