J
Jeff Paciga
I have been reading about the problems associated with vector<bool>.
Unfortunately, the usual work-arounds aren't viable for me, but I have
never seen anyone mention using a class that behaves like a bool:
class FakeBool
{
public:
FakeBool() : b_(false) {}
FakeBool(bool b) : b_(b) {}
operator bool() { return b_; }
bool* operator&() { return &b_; }
private:
bool b_;
};
int main()
{
vector<FakeBool> v(5);
bool* p = &v[0];
}
I presume this solution is never mentioned because it is obviously
wrong,
but it seems to work well for me. Am I missing something?
Unfortunately, the usual work-arounds aren't viable for me, but I have
never seen anyone mention using a class that behaves like a bool:
class FakeBool
{
public:
FakeBool() : b_(false) {}
FakeBool(bool b) : b_(b) {}
operator bool() { return b_; }
bool* operator&() { return &b_; }
private:
bool b_;
};
int main()
{
vector<FakeBool> v(5);
bool* p = &v[0];
}
I presume this solution is never mentioned because it is obviously
wrong,
but it seems to work well for me. Am I missing something?