Boost logo

Boost Users :

Subject: Re: [Boost-users] boost:any/boost::variant for integral/floating type
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-06-01 10:42:08


On 06/01/10 08:12, Mathieu Malaterre wrote:
> Hi,
>
> I am looking at boost::any and boost::variant which seems to be very
> usefull additions to C++ for building heterogenous containers.
> However in my case I need to build something that would be:
> - type safe
> - can only contains integral/floating type
[snip]
> Did I miss anything in boost ? Is boost::variant my best option (when
> only using fundamental types) ?
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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net