Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-02-25 15:14:14


Daniel Frey <daniel.frey_at_[hidden]> writes:

> David Abrahams wrote:
>>
>> Daniel Frey <daniel.frey_at_[hidden]> writes:
>>
>> > That won't work as you made it a nested struct so it is still different
>> > for all instantiations. I think Dave meant to go for this one:
>>
>> Yup, that's what I meant. BTW, so this safe_bool thing can get
>> further re-used it might make sense to make a special friend class
>> which just has access to the type... or at that point, just make the
>> type publicly accessible.
>
> Can you elaborate a bit? I imagine that although the technical
> implementation might be identical, the sematics of the names could be a
> problem.

Can you elaborate a bit? How could the semantics be a problem?

> Helping the compiler to remove unneeded instantiations is a
> good thing, but it shouldn't affect readability, so I'd like to see some
> more concrete uses and whether we can use safe_bool (or any other name)
> that matches all these "typical" uses.

namespace boost
{
   struct safe_bool
   {
       int value;
       typedef int safe_bool::*type;
   };
}

struct myclass
{
   operator boost::safe_bool::type() const
   {
        return expression ? &boost::safe_bool::value : 0;
   }
};

HTH,

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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