Boost logo

Boost :

From: Schoenborn, Oliver (Oliver.Schoenborn_at_[hidden])
Date: 2002-10-07 09:18:21


> -----Original Message-----
> From: Daniel Frey [mailto:daniel.frey_at_[hidden]]
>
> I haven't followed the discussion closely, so please forgive if this has
> been suggested before or if I misunderstood the problem. You want ptr<T>
> to be usable as a ptr< const T >? What about:
>
> template< typename T > class ptr
> {
> ...
>
> public:
> operator const ptr< const T >&() const
> {
> return reinterpret_cast< const ptr< const T >& >( *this );
> }
>
> ...
> };
>
> Or is reinterpret_cast considered too
> dangerous/non-portable/...? For my
> own pointer-class, this works well (GCC 3.2).

Interesting, I'd like to know if there are any situations where it is not
safe. Since the member data and functions for T and const T are exactly the
same perhaps this is safe. But I would guess that unless something like that
is specified in the standard (about the action of reinterpret_cast on
template classes of T vs on const T), it's probably non-portable in theory
(though in practice it may be). Hopefully some of the experts on the list
will share their opinions. Have you posted this to other newsgroups like
c.l.cpp.m?

Oliver


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