problems with binary variant visitors in 1.31

Great job with the 1.31 release! Just wondering if anybody else observerved this kind of problems before. When compiling the code below with MSVC 7.1, I am getting this error: test.cpp(123) : error C2039: 'set' : is not a member of 'my_type::test1'. GCC 3.2.3 gives a compilation error as well. template< typename T > struct binary_variant_visitor : public ::boost::static_visitor<> { T& obj_; binary_variant_visitor( T& obj ) : obj_(obj) {} template< typename VT1, typename VT2 > void operator()( VT1& v1, VT2& v2 ) { obj_.visit( v1, v2 ); } }; struct my_type { struct test1 { test1(); ~test1(); }; struct test2 { ~test2(); template< typename T > void set( T& ); }; typedef ::boost::variant<test1,test2> var; var d_; template< typename U > void visit( test1& t, U& u ) //test1 doesn't have set() { } template< typename T, typename U > void visit( T& t, U& u ) { t.set(u); } const var& data() const { return d_; } }; main() { my_type t1, t2; binary_variant_visitor<my_type> v(t1); ::boost::apply_visitor(v, t1.data(), t2.data() ); } If I change the last line to ::boost::apply_visitor(v, t1.d_, t2.d_ ); it works fine on both compilers. I guess it has something to do with how apply_visitor derives the parameter types. Eugene __________________________________ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html

I haven't tried any of this code, but I just happened to notice this while glancing... On Fri, Feb 06, 2004 at 02:29:53AM -0800, E. Gladyshev wrote: ...
struct my_type { ... var d_;
template< typename U > void visit( test1& t, U& u ) //test1 doesn't have set() { }
template< typename T, typename U > void visit( T& t, U& u ) { t.set(u); }
const var& data() const { return d_; } };
main() { my_type t1, t2;
binary_variant_visitor<my_type> v(t1); ::boost::apply_visitor(v, t1.data(), t2.data() ); }
If I change the last line to ::boost::apply_visitor(v, t1.d_, t2.d_ );
it works fine on both compilers.
data() returns a "const &", whereas I think .d_ will be non-const. Offhand I am kinda surprised that any of the visit() methods (which all want non-const) end up matching, but I have not studied the code very deeply. In any case, maybe adding a
var& data() { return d_; }
in addition to
const var& data() const { return d_; }
will help. -- -Brian McNamara (lorgon@cc.gatech.edu)

--- Brian McNamara <lorgon@cc.gatech.edu> wrote: [...]
data() returns a "const &",
Exactly, pilot error. :) I had to write ::boost::apply_visitor(v, t1.d_, t2.data() ); Eugene __________________________________ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html
participants (2)
-
Brian McNamara
-
E. Gladyshev