Google-apps
Hoofdmenu

Post a Comment On: C0DE517E

"Hacking bools idea"

2 Comments -

1 – 2 of 2
Anonymous Anonymous said...

Something like :

struct sHeavyBool
{
explicit sHeavyBool(const int t_) : t(t_) {};
explicit sHeavyBool(const unsigned int t_) : t(t_) {};
sHeavyBool(const bool t_) : t(t_) {};
explicit sHeavyBool(const char t_) : t(t_) {};
sHeavyBool() {};
sHeavyBool(const sHeavyBool & t_) : t(t_.GetValue()){}
sHeavyBool & operator=(const sHeavyBool & rhs)
{
t = rhs.GetValue();
return *this;
}
sHeavyBool & operator=(const int t_)
{
t = (t_ == 0)?false:true;
return *this;
}
operator const bool & () const { bool t2 = GetValue(); return t; }
operator bool & () { bool t2 = GetValue(); return t; }
bool operator==(const sHeavyBool & rhs) const { return GetValue() == rhs.GetValue(); }
bool operator==(const bool & t_) const { return GetValue() == t_; }
bool operator<(const sHeavyBool & rhs) const { return GetValue() < rhs.GetValue(); }

bool GetValue() const
{
#ifdef _DEBUG
if((t != true)&&(t != false))
{
if( (explicitChar == 0xCD) || (explicitChar == 0xCC) )
{
assert( "Boolean not initialized" && false );
}
else
{
assert( "Boolean initialized strangely" && false );
}

}
#endif
return t;
}

protected:
union
{
bool t;
unsigned char explicitChar;
};
};

and then typedef your own bool to sHeavyBool ?

April 4, 2011 at 3:15 PM

Anonymous Anonymous said...

I'd love to see class injection, replacing bool and int as you say. These would be handy:

int8_t x = 255 + 1; // Assert int8_t has overflowed!

void* p = GetPointer();
if (p) // Assert, pointer is not convertable to bool (Have to use p != nullptr)

April 5, 2011 at 1:39 AM

You can use some HTML tags, such as <b>, <i>, <a>

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot