Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-08-18 06:41:51


Jeff Williams wrote:
> Simply small change, curious as to what others think:
>
> I'll illustrate with a trivial example:
>
> struct foo { virtual ~foo() { } };
> struct bar : foo { };
>
> typedef shared_ptr<foo> fooptr;
> typedef shared_ptr<bar> barptr;
>
> void some_func(weak_ptr<foo> wf)
> {
> barptr pb = wf.lock<bar>();
> }
>
> // currently the way to do this is (as I am sure everyone knows)
> void some_func(weak_ptr<foo> wf)
> {
> barptr pb = dynamic_pointer_cast<bar>(wf.lock());
> }
>
> My suggestion seems easier to read. Would require no additional
> overhead and would preserve existing behavior.

However, there is no indication that wf.lock<bar> does a cast, or which kind
of cast is being done.

> I suppose you could provide a static and dynamic version:
>
> lock_static<bar> and lock_dynamic<bar>
>
> Any thoughts? Or is the general concensus that ideas like this are
> something indivudual people should do in their own source?

Something like that. In general, libraries expose a "minimal but complete"
interface, and utility functions are left to the users (whose preferences
usually differ).

"Boilerplate" functions or components (nearly every user needs to have them,
and they are a de-facto standard) are an exception, of course.


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