
On 06/03/10 04:22, Mathieu Malaterre wrote:
On Tue, Jun 1, 2010 at 4:42 PM, Larry Evans <cppljevans@suddenlink.net> wrote: [snip]
Look out for the boost:;variant trap revealed by the post:
http://article.gmane.org/gmane.comp.lib.boost.user/58791
The problem occurs when one component can be constructed from another component. as suggested by this quote from the above post:
When bool is added to variant, the statement variant = "hello world" ; calls bool constructor.
I think something similar may happen here, but maybe the problem can be solved by some order of the bound components. Maybe putting more "stringent" components either first or last. That way, maybe the correct one would be selected when the assignment is made.
Thanks for the warning. My base type are fundamental type, so I should not suffer from this implicit cast. The 1st attachment, when compiled with gcc4.4 I, gives errors in 2nd attachment.
When the '#if 1' is replaced with '#if 0' it compiles OK, indicating that you must explicitly cast the argument type to avoid the ambiguity error in this particular case. HTH. -Larry In file included from /home/evansl/prog_dev/boost-svn/ro/trunk/boost/variant.hpp:17, from variant_implicit_conversion.cpp:5: /home/evansl/prog_dev/boost-svn/ro/trunk/boost/variant/variant.hpp: In member function 'void boost::variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>::convert_construct(T&, int, mpl_::false_) [with T = const double, T0_ = int, T1 = float, T2 = boost::detail::variant::void_, T3 = boost::detail::variant::void_, T4 = boost::detail::variant::void_, T5 = boost::detail::variant::void_, T6 = boost::detail::variant::void_, T7 = boost::detail::variant::void_, T8 = boost::detail::variant::void_, T9 = boost::detail::variant::void_, T10 = boost::detail::variant::void_, T11 = boost::detail::variant::void_, T12 = boost::detail::variant::void_, T13 = boost::detail::variant::void_, T14 = boost::detail::variant::void_, T15 = boost::detail::variant::void_, T16 = boost::detail::variant::void_, T17 = boost::detail::variant::void_, T18 = boost::detail::variant::void_, T19 = boost::detail::variant::void_]': /home/evansl/prog_dev/boost-svn/ro/trunk/boost/variant/variant.hpp:1372: instantiated from 'boost::variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>::variant(const T&) [with T = double, T0_ = int, T1 = float, T2 = boost::detail::variant::void_, T3 = boost::detail::variant::void_, T4 = boost::detail::variant::void_, T5 = boost::detail::variant::void_, T6 = boost::detail::variant::void_, T7 = boost::detail::variant::void_, T8 = boost::detail::variant::void_, T9 = boost::detail::variant::void_, T10 = boost::detail::variant::void_, T11 = boost::detail::variant::void_, T12 = boost::detail::variant::void_, T13 = boost::detail::variant::void_, T14 = boost::detail::variant::void_, T15 = boost::detail::variant::void_, T16 = boost::detail::variant::void_, T17 = boost::detail::variant::void_, T18 = boost::detail::variant::void_, T19 = boost::detail::variant::void_]' variant_implicit_conversion.cpp:20: instantiated from here /home/evansl/prog_dev/boost-svn/ro/trunk/boost/variant/variant.hpp:1299: error: call of overloaded 'initialize(void*, const double&)' is ambiguous /home/evansl/prog_dev/boost-svn/ro/trunk/boost/variant/detail/initializer.hpp:89: note: candidates are: static int boost::detail::variant::make_initializer_node::apply<BaseIndexPair, Iterator>::initializer_node::initialize(void*, typename boost::call_traits<typename boost::unwrap_recursive<typename boost::mpl::deref<Iterator>::type>::type>::param_type) [with BaseIndexPair = boost::mpl::pair<boost::detail::variant::make_initializer_node::apply<boost::mpl::pair<boost::detail::variant::initializer_root, mpl_::int_<0> >, boost::mpl::l_iter<boost::mpl::list2<int, float> > >::initializer_node, mpl_::int_<1> >, Iterator = boost::mpl::l_iter<boost::mpl::list1<float> >] /home/evansl/prog_dev/boost-svn/ro/trunk/boost/variant/detail/initializer.hpp:89: note: static int boost::detail::variant::make_initializer_node::apply<BaseIndexPair, Iterator>::initializer_node::initialize(void*, typename boost::call_traits<typename boost::unwrap_recursive<typename boost::mpl::deref<Iterator>::type>::type>::param_type) [with BaseIndexPair = boost::mpl::pair<boost::detail::variant::initializer_root, mpl_::int_<0> >, Iterator = boost::mpl::l_iter<boost::mpl::list2<int, float> >] make: *** [/home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_4n/boost-svn/ro/sandbox/variadic_templates/libs/composite_storage/sandbox/pack/variant_implicit_conversion.o] Error 1