Boost logo

Boost :

From: Pablo Aguilar (pablo.aguilar_at_[hidden])
Date: 2005-07-14 16:19:38


Just a thought...

Could replacing weak_ptr with optional<weak_ptr> do the job?

Pablo Aguilar

"Jaap Suter" <boost_at_[hidden]> wrote in message
news:003101c588ad$ce174b40$4119059a_at_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


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