Boost logo

Boost :

From: Daniel Frey (d.frey_at_[hidden])
Date: 2002-10-07 19:01:49


On Mon, 07 Oct 2002 20:22:59 +0200, David Abrahams wrote:

> Why do you say that? reinterpret_cast has completely
> implementation-dependent behavior. You can't know what it will do
> without reading the manual for each compiler you're targeting.
> static_cast has behavior that's specified by the standard.

OK, you win :) How about a boostified helper?

  template< typename T, typename S > T& pointer_cast( S* const& p )
  {
    return *static_cast< T* >(
      static_cast< void* >(
        const_cast< typename ::boost::remove_cv< S >::type* >( p )
      )
    );
  }

Can be used easily, I tested it already. Although I wonder if someone
will jump up now and say it's not portable ;))

(Indeed it was the constness that was biting me when playing with it
originally, so a helper would really... well... help)

Regards, Daniel


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