$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Joel de Guzman (joel_at_[hidden])
Date: 2003-11-27 02:59:08
Joel de Guzman <joel_at_[hidden]> wrote:
> Daryle Walker <darylew_at_[hidden]> wrote:
>> On 11/24/03 10:47 PM, "Joel de Guzman" <joel_at_[hidden]> wrote:
> 
>> BTW, Spirit does have a solution for this problem, right?  Otherwise, you
>> have a major bug!
>> 
>> (Note that no matter how you define Boolean-conversion, you need to
>> explicitly provide operators == and != for your type, "poisoned" if such
>> objects aren't supposed to be comparable, and conventional if they are.)
> 
> You must've missed this:
> 
> Second take:
> 
>     template <typename T>
>     struct safe_bool
>     {
>         int* dummy;
>         typedef int* safe_bool::*type;
>     };
> 
>     template <typename T>
>     inline typename safe_bool<T>::type
>     make_safe_bool(bool cond)
>     {
>         return cond ? &safe_bool<T>::dummy : 0;
>     }
> 
> Can you spot some problems with this too?
Some tweaks:
    template <typename T>
    struct safe_bool
    {
        T* dummy;
        typedef T* safe_bool::*type;
    };
    template <typename T>
    inline typename safe_bool<T>::type
    make_safe_bool(bool cond)
    {
        return cond ? &safe_bool<T>::dummy : 0;
    }
Here's a sample:
        operator safe_bool<match<nil_t> >::type() const
        {
            return make_safe_bool<match<nil_t> >(len >= 0);
        }
Cheers,
-- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net