
On Tue, Jun 1, 2010 at 4:42 PM, Larry Evans
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.
Thanks for the warning. My base type are fundamental type, so I should not suffer from this implicit cast. Thanks -- Mathieu