Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 2000-01-19 09:42:34


Greg Colvin wrote:

> > When similar functionnality was desired, Matt Austern
> > proposed in London the use of do_static_cast,
> > do_const_ etc for generalised allocator::pointer.
> > I tend to like that.
>
> I didn't like it, and argued that it was not necessary
> for allocator::pointer. But shared_ptr never did meet
> the requirements for allocator::pointer anyway.

I am not arguing about the need for pseudo-casts for
generalized allocator::pointer here, merely pointing out
that there was a precedent for the do_xxx spelling.

> > I propose (untested code):
>
> Do we really need anything beyond dynamic cast? The reinterpret
> cast is too dangerous,

And I did _not_ proposed reinterpret_cast.

> and it seems that static cast is already
> provided for:
> shared_ptr<Derived> derived(new Derived);
> shared_ptr<Base> base(derived);

Hum not really (the above is implicit_cast).

> > #define DEFINE_PSEUDO_CAST(THE_CAST) \
> > template <typename To, typename From> \
> > shared_ptr<To> do_ ## THE_CAST ## _cast (const shared_ptr<From>& p) \
> > { \
> > ++*p.pn; \
> > return shared_ptr<To> (THE_CAST ## _cast<To*> (p.px), p.pn); \
> > }
> >
> > DEFINE_PSEUDO_CAST(const)
> > DEFINE_PSEUDO_CAST(static)
>
> I don't think the macros are worth the bother for such small
> functions.

Well, at first I had in mind the repetition of four time
the same thing (static, dynamic, const, reinterpret). After
I realised that there were only two repetitions.

I currently use macros a lot.

-- 
Valentin Bonnard

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