Modify

Ticket #810 (new Feature Requests: None)

Opened 9 years ago

Last modified 21 months ago

support for weak_ptr binding

Reported by: nobody Owned by: pdimov
Milestone: To Be Determined Component: smart_ptr
Version: None Severity: Optimization
Keywords: Cc: jwakely.boost@…

Description (last modified by pdimov) (diff)

Hello,

recently i faced with problem - i was not able to pass weak_ptr to bind() function. I started to study why and found there is no support for this in boost.

As result, me and my friend wrote "get_pointer" version
which accepts weak_ptr. 

At actual call moment, implementation uses weak_ptr::lock() to get shared_ptr. If retrieved shared_ptr is invalid, then exception of type "disposed_exception" thrown.

This code was tested on Windows XP SP2 with following compilers: VC6, VC7, VC7.1, VC8, g++ 3.2.3 (MinGW), g++ 3.4.4 (Cygwin).

If you find this code is useful for someone else me, please add to boost (it's actually not a library, this is why i'm poosting it to "patches"). You can find sources + test app in attachment.


Thank you,
Dmytro Gokun

Attachments

bind_weak_ptr.zip Download (2.2 KB) - added by pdimov 8 years ago.

Change History

comment:1 Changed 8 years ago by btmore@…

Are there any plans to add this type of functionality?

This would be very useful in my current project, but I'd rather stick with upstream instead of patching boost locally.

Changed 8 years ago by pdimov

comment:2 Changed 8 years ago by pdimov

  • Type changed from Patches to Feature Requests
  • Severity set to Optimization
  • Milestone set to To Be Determined

Moved to Feature Requests, restored attachment.

comment:3 Changed 8 years ago by andy@…

For what it's worth, I second the request for this functionality. I was thinking about attempting to write a version myself for submission when I stumbled across this trac entry. I think that this form of bind would be extremely useful. I can't think of a nicer generic way to break a shared_ptr dependency while still maintaining decoupling using boost bind and function.

comment:4 Changed 6 years ago by Jonathan Wakely <jwakely.boost@…>

  • Cc jwakely.boost@… added

comment:5 Changed 4 years ago by joseph.j.mudnackal@…

is this feature gonna be added anytime soon?

comment:6 Changed 21 months ago by pdimov

  • Status changed from assigned to new
  • Description modified (diff)
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.