Problem transforming a vector<bool> to a vector<any>
Hi everyone, 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::vectorstd::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. Thanks, Fabrice -- View this message in context: http://www.nabble.com/Problem-transforming-a-vector%3Cbool%3E-to-a-vector%3C... Sent from the Boost - Users mailing list archive at Nabble.com.
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::vectorstd::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
Steven Watanabe-4 wrote:
AMDG
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
Hi Steven, and thanks for your answer. I've looked it up, and indeed vector<bool> is a problematic structure... Clearly the work of an evil spirit. Anyway, knowing that, it will be easier for me to find a workaround. Many thanks, Fabrice -- View this message in context: http://www.nabble.com/Problem-transforming-a-vector%3Cbool%3E-to-a-vector%3C... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
Fabrice_CBA
-
Steven Watanabe