vector<FakeBool>

From: Jeff Paciga (jeff.paciga_at_gmail.com)
Date: 10/05/04


Date: 5 Oct 2004 08:58:22 -0700

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?