Boost logo

Boost Users :

Subject: Re: [Boost-users] Variant bool bug
From: Surya Kiran Gullapalli (suryakiran.gullapalli_at_[hidden])
Date: 2010-05-21 06:27:40


On Fri, May 21, 2010 at 15:09, Robin <robin_at_[hidden]> wrote:

> Hi
>
> When I add a bool into the variant, the get int version fails (VC2008 SP1,
> boost
> 1.42.0, sorry earlier was mentioning wrong version 1.37.0)
>
> typedef boost::variant <bool, int, string> VariantType;
>
> VariantType variant;
> variant = "hello world";
> string stringTest = boost::get <string> (variant);
> cout << stringTest.c_str () << endl;
>
> variant = 5;
> int intTest = boost::get <int> (variant); // Fails
> cout << intTest << endl;
>

When bool is added to variant, the statement
variant = "hello world" ;
calls bool constructor.

The one which is actually crashing is not int .. it is string which is
crashing. because the "hello world" is not a *string* type strictly
speaking. it is *const char**. This is converted to bool and calls bool
constructor.

Surya



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