Skip to main content
GameDev.net gamedev.net
🔒 Locked

std::vector and bool

Started by Evil Steve Jul 4, 2006 at 7:24 AM 4 replies 4.8k views
Original Post
Evil Steve
Evil Steve
Hi all, I'm doing some bit-stuffing code at the moment, and I figured I could use std::vector to do that, since it's specialised (apparently). I know this is valid: std::vector foo; // Stuff things into foo int* pData = &foo[0]; Since vector storage is contiguous. However, CodeWarrior spazzes out when I do this: std::vector foo; // Stuff a multiple of 8 bits into foo void* pData = &foo[0]; The error I get is:
Quote:
illegal explicit conversion from 'std::__bit_iterator>, false>' to 'void *'
I presume that's because CodeWarrior isn't using a vector at all. Is what I'm trying to do valid (I.e. is it a compiler error), or are you not allowed to do this with a vector of bools? For the moment, I'm having to convert the vector into a void* manually, which isn't particularly efficient. Is there some std::copy I could use to do this which would be as efficient as direct pointer access? Cheers, Steve
rip-off
rip-off
The bool values in std::vectors are implemented using single bits. You cannot get a reference or pointer to a bit, so you get an error.

This is the downside to the apparent "optimisation" that is std:vector/
Evil Steve
Evil Steve
Quote:
Original post by rip-off
The bool values in std::vectors are implemented using single bits. You cannot get a reference or pointer to a bit, so you get an error.

This is the downside to the apparent "optimisation" that is std:vector/
Ah well, that's what I thought. I'll just it my way then.

Thanks for the reply

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.