"Jeff Paciga" <je*********@gm ail.com> wrote in message
news:81******** *************** ***@posting.goo gle.com...
> vector<FakeBool > v(5);
> bool* p = &v[0];
Note that trying to access subsequent items with something
like p[1] will lead to undefined behavior (UB) - a no-no
(even though it may work on your specific platform).
Is that because sizeof(FakeBool ) may be greater than sizeof(bool)
because of byte alignment? I admit that I am quite confused about
how structs are stored internally, but I was hoping that since it was
just one bool that I was ok. I guess not.
Unfortunately, there is no guarantee that sizeof(FakeBool )==sizeof(bool) ,
even though it is likely to be the case on many platforms.
Why are the "usual work-arounds" not viable for you?
Well, I want to be able to pass &v[0] to some crappy API that
needs an array of bools, so I can't use vector<char>, or
deque<bool>. I guess I will just have to do things the old-fashioned way.
Eventually, one option you could also consider is to use
an std::basic_stri ng<bool> ... I haven't looked into it,
but you will then be able to use the data() or c_str()
member functions for *read-only* access to a contiguous
array of bools.
Other than that, I'm afraid the standard library does
not offer a solution here.
Kind regards,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form