Q:

Converting custom integer wrapper to boolean

Suppose i have a custom wrapper around a primitive C++ type:
class myInt
{
    public:
        /*stuff here*/
    private:
        unsigned int data;
}

How can i make  
myInt mi;  
if(mi){...}  

behave in a way you would expect from a normal integer?
All i can think of is to write an explicit boolean cast, or perhaps override operator==.
Something like:  
if(bool(mi)){...}
if(mi.toBool()){...}
if(mi==true){..}

All these do serve the purpose but look quite ugly and artificial.
Is there another option i am missing?

A:

The best option is to drop the wrapper altogether.

A:

You can make your following cast operator, something like:
class myInt
{
    public:
        operator bool() const { return data != 0; }

    private:
        unsigned int data;
}

It is by default implicit (it means that it will be used every time the compiler finds it does need a bool and you provides a myInt). Since c++11 you can mark it as explicit, forcing the usage to be restricted to explicit cast, before that it was always implicit.
But you should note that it is often a bad idea and should be avoided: check the safe bool idiom for more lecture.
Another option close to your desire and a lot safer is the overload of the ! operator:
class myInt
{
    public:
        bool operator!() const { return data == 0; }

    private:
        unsigned int data;
}

