From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-07-23 17:54:24
From: "Rene Rivera" <grafik666_at_[hidden]>
> [2002-07-23] Craig Henderson wrote:
> >> There's a trick I use to get rid of the need for "extra" template
> >> that might be usefull here...
> >> template<typename Target, typename Source, typename E>
> >> inline Target lexical_cast(Source arg, E& interpreter =
> >> (*reinterpret_cast<E*>(0))
> >> ...
> >I'm not sure that dereferencing a null pointer in this way to create a
> >reference this is a good idea. Not least, my test on MSVC does not
> > short &t = *(reinterpret_cast<short*>(0));
> >generates an error
> > error C2040: 't' : 'short &' differs in levels of indirection from
> Not usually a good idea unless you have tight control of it's use. It's
> bad MSVC chokes on it though :-(
Let me be clear about this: Applying * to a NULL pointer invokes undefined
That means that *xxxx_cast<T*>(0) is wrong for any T and any xxxxx, at
least in portable code.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk