Re: [boost] FW: [Boost-users] [variant] make_recursive_variant and std::map

AMDG "Richard Crossley" wrote:
Cross posted from the boost users list... Can anyone help me out here?
http://thread.gmane.org/gmane.comp.lib.boost.user/23608/focus=23608
Regards,
Richard.
Ok. I've finally figured out what's happening. It looks like a compiler bug introduced in sp1. Here is the simplest I could reduce it to. struct undefined; template<class T> void f(T) { } template<class T> struct A { }; template<class T> struct B { }; template<class T> struct C { T t; }; int main() { f((A<B<C<undefined> > >*)0); } This causes msvc to instantiate C<undefined>. Note that just B<C<undefined> > is not enough. All three templates are needed. Qualifying the call to f fixes the problem, so this bug appears to be caused by ADL. Now for your problem. The function calls that need to be qualified are visitation_impl_invoke and visitation_impl_invoke_impl in <boost/variant/detail/visitation_impl.hpp>. When I tried that it compiled. Until this is fixed you can use recursive_wrapper directly. struct my_map; typedef boost::variant<int, boost::recursive_wrapper<my_map> > element; struct my_map : std::map<float, element> { my_map(const std::map<float, element>& arg) : std::map<float, element>(arg) {} friend std::ostream& operator<<(std::ostream& os, const my_map& self) { os << static_cast<const std::map<float, element>&>(self); } }; In Christ, Steven Watanabe

Hi Steve, Thanks for your help, though I'm somewhat uncertain as to what's going on. Your example would appear to be able to be simplified further or am I misunderstanding? struct undefined; template<class T> struct C { T t; }; void f(void*){} int main() { C<undefined> * p = 0; // OK f(p); // ERROR } Anyway, using your inheritance idea along with Caleb Epstein's sample code e.g. struct map_; typedef boost::mpl::vector<int,float,std::string>::type key_types; typedef boost::mpl::push_back<key_types,map_>::type element_types; typedef boost::make_variant_over<key_types>::type key; typedef boost::make_variant_over<element_types>::type element; typedef struct map_ : std::map<key,element>{} map_t; Will build with VC8SP1. Not as pretty, but it gets things going. Regards, Richard.
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost- bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: 29 December 2006 01:00 To: boost@lists.boost.org Subject: Re: [boost] FW: [Boost-users] [variant] make_recursive_variant and std::map
AMDG
"Richard Crossley" wrote:
Cross posted from the boost users list... Can anyone help me out here?
http://thread.gmane.org/gmane.comp.lib.boost.user/23608/focus=23608
Regards,
Richard.
Ok. I've finally figured out what's happening. It looks like a compiler bug introduced in sp1. Here is the simplest I could reduce it to.
struct undefined;
template<class T> void f(T) { }
template<class T> struct A { }; template<class T> struct B { }; template<class T> struct C { T t; };
int main() { f((A<B<C<undefined> > >*)0); }
This causes msvc to instantiate C<undefined>. Note that just B<C<undefined> > is not enough. All three templates are needed. Qualifying the call to f fixes the problem, so this bug appears to be caused by ADL.
Now for your problem. The function calls that need to be qualified are visitation_impl_invoke and visitation_impl_invoke_impl in <boost/variant/detail/visitation_impl.hpp>. When I tried that it compiled.
Until this is fixed you can use recursive_wrapper directly.
struct my_map; typedef boost::variant<int, boost::recursive_wrapper<my_map> > element; struct my_map : std::map<float, element> { my_map(const std::map<float, element>& arg) : std::map<float, element>(arg) {} friend std::ostream& operator<<(std::ostream& os, const my_map& self) { os << static_cast<const std::map<float, element>&>(self); } };
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Richard Crossley
-
Steven Watanabe