$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Dan Nuffer (dnuffer_at_[hidden])
Date: 2000-11-03 14:29:34
Dan Nuffer wrote:
> 
> Darin Adler wrote:
> >
> > on 11/3/00 10:10 AM, Dan Nuffer at dnuffer_at_[hidden] wrote:
> >
> > > Also, I am using gcc 2.95.2 on Caldera OpenLinux 2.4 and any_cast wouldn't
> > > compile. gcc was giving the following warning:
> > >
> > >   src/tokenizer/any.hpp:179: parse error before `>'
> > >
> > > It didn't like the to_ptr<ValueType> for some strange reason.  It
> > > normally accepts this syntax...
> > > To get around the problem I had to add a little template helper:
> > >
> > >   template <typename ValueType>
> > >   const ValueType * to_ptr_helper( ValueType* ) const
> > >   {
> > >       return const_cast<any *>(this)->to_ptr<ValueType>();
> > >   }
> >
After fiddling around some more, I found an even better way to get g++
to compile this.
There is no need for to_ptr_helper, simply change any_cast like this:
    template<typename ValueType>
    ValueType any_cast(const any & operand)
    {
        const ValueType * result =
                          operand.template to_ptr<ValueType>();
        if(!result)
        {
            throw bad_any_cast();
        }
        return *result;
    }
Adding "template" in the middle of "operand.to_ptr" looks strange, but
it's valid and helps g++ parse it correctly.
--Dan Nuffer