Boost logo

Boost :

Subject: Re: [boost] safe bool operator
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2010-03-01 16:06:37


On 1 March 2010 15:36, Domagoj Saric <domagoj.saric_at_[hidden]> wrote:
>
>    //or by using a macro
>    BOOST_SAFE_BOOL_FROM_FUNCTION( some_is_valid_function() )
>

Is there a reason it can't just always look at operator!?

I've been using a macro like this, since I don't need the workarounds:

#define OPERATOR_SAFE_BOOL(for_type) \
    typedef bool (for_type::*unspecified_bool_type)() const; \
    operator unspecified_bool_type() const { \
        return !*this ? 0 : &for_type::operator!; \
    }

so then it's just

class my_class
{
public:
   bool operator!() const;
   OPERATOR_SAFE_BOOL(my_class)
};


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk