Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-07-24 11:46:58

On Tuesday 24 July 2001 09:04, you wrote:
> From: <greg_at_[hidden]>
> > This looks like a good start, thanks. I think do_dynamic_cast is the
> > name we previously agreed on for your shared_dynamic_cast, and that
> > we wanted a version that worked for raw pointers as well.
> If do_dynamic_cast is supposed to be a generalization of dynamic_cast:
> template<class R, class T> R do_dynamic_cast(T /* const */ &);
> (dynamic_cast<U*> returns U*, dynamic_cast<U&> returns U&)
> then dynamic-casting a shared_ptr would look like
> do_dynamic_cast<shared_ptr<X> >(y); // 1
> whereas with a shared_ptr-specific cast the syntax would be
> shared_dynamic_cast<X>(y); // 2
> I prefer (2). (1) is more generic but I can't see how the genericity would
> be exploited.
> --
> Peter Dimov
> Multi Media Ltd.

(1) also has the advantage of being syntactically identical to dynamic_cast.
It seems like a named cast that doesn't cast exactly to the type named in the
angle brackets shouldn't have the postfix _cast.

To make do_dynamic_cast<> really useful for functions accepting generic
pointer-like types, one might also need the ability to rebind a pointer, i.e.,

        pointer_rebind<boost::shared_ptr<int>, float>::pointer

would return the type boost::shared_ptr<float>. Then it would be possible to
write code to accept generic pointer types and perform casts on them with

Boost list run by bdawes at, gregod at, cpdaniel at, john at