
Just a thought... Could replacing weak_ptr with optional<weak_ptr> do the job? Pablo Aguilar "Jaap Suter" <boost@jaapsuter.com> wrote in message news:003101c588ad$ce174b40$4119059a@unknown...
Are there compelling reasons not to add such a member function, i.e. a different shared_ptr implementation wouldn't be able to provide such a function?
A friend of mine actually came up with a use case in his code, which is what prompted this question. In pseudo-code, it looked like this:
struct guarded_memory { void* memory; weak_ptr guard;
guarded_memory(void* m) : guard(), memory(m) {} guarded_memory(void* m, weak_ptr g) : guard(g), memory(m) {}
void access() { if (guard.never_been_assigned_to_before()) { // no guard means always accessible do_something_with(memory); } else { if (shared_ptr p = guard.lock()) { do_something_with(memory); } } } };
[snip comments]
Thanks,
Jaap Suter