|
Boost Users : |
Subject: Re: [Boost-users] Inconsistent with variant with bool
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-05-22 12:01:55
AMDG
Robin wrote:
> I'm facing a inconsistent behavior with Variant when bool is defined. The below
> code will return i as 0
>
> typedef boost::variant <int> VariantType;
>
> VariantType variant;
> int i = boost::get <int> (variant)); // default to 0
>
> If I set a bool in the variant
>
> typedef boost::variant <bool, int> VariantType;
>
> VariantType variant;
> int i = boost::get <int> (variant)); // this throws fail get
>
> Is it intended behavior?
>
Yes. A default constructed variant contains the first variant type,
so your variant contains a bool, not an int.
In Christ,
Steven Watanabe
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