From: Jeff Williams (jwilliams_at_[hidden])
Date: 2004-08-17 16:32:36


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.

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?

Jeff