Boost logo

Boost Users :

Subject: Re: [Boost-users] Problem transforming a vector<bool> to a vector<any>
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-02-03 21:27:07


AMDG

Fabrice_CBA wrote:
> I am working on a project in which I'm using a "simplified" version of the
> boost::any library. By simplified, I mean that I got rid of the #defines and
> made it independent from the rest of boost. The changes are very small, and
> in my opinion shouldn't impact much the class, since the general structure
> is still there. My implementation is attached to this message.
> http://www.nabble.com/file/p21822878/Any.h Any.h
>
> However I am having a problem transferring a vector<bool> into a
> vector<any>. It works for any other types I've tested, only booleans fail.
> Here is an example:
>
> std::vector<std::string> source0(1, "SomeString");
> std::vector<long> source1(1, 666);
> std::vector<bool> source2(1, true);
> std::vector<double> source3(1, 6.66);
>
> std::vector<any> destination;
> destination.push_back(source0[0]);
> destination.push_back(source1[0]);
> destination.push_back(source2[0]);
> destination.push_back(source3[0]);
>
> When checking what is in destination[2], it seems it only holds {...}, and
> not the original {true}. Whereas it works perfectly for the other values.
>
> Any idea on what I'm doing wrong? Any help appreciated.
>

vector<bool> strikes again...

The problem is that for vector<bool> (only)
source2[0] is not of type bool. You need to cast.

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