"Philippe A. Bouchard" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

[...]

> int main()
> {
>     optional<B> b;
>     optional<C> c;
>
>     foo(b);
>     //foo(c);
> }

BTW implicit cast to reference types are not implicit under GCC, they have
to be called explicitly.  Template casts do not seem to be defined in the
standard...:

template <typename T>
    struct optional
    {
        template <typename U>
            operator optional<U> const & () const
            {
                return * reinterpret_cast<optional<U> const *>(static_cast<U
const *>(reinterpret_cast<T const *>(storage_)));
            }

    ...
 };

inline void foo(optional<A> const &)
{
}

int main()
{
    optional<B> b;

    //foo(b);
    foo(b.template operator optional<A> const & <A> ());
}


Also, the advantage of casts to reference types is that they do not create
any temporary objects implicitly.  I do not see in what it can be dangerous.

What do you think?



Philippe A. Bouchard




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to