Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signals library which tracks slots lifetime automatically

I need a signals/slots c++ library with one specific feature that the signals automatically disconnect the slot when the object with the slot is destroyed.

Boost::signals2 offers this feature only for object created with boost::shared_ptr and I want to keep using std::shared_ptr everywhere. There is an option to make it work with std::shared_ptr but it requires writing some specialized templates and there is no info how it should like and generally I'd prefer to avoid it (unless there is the code somewhere in the internet, but I couldn't find it).

I know that Qt signals have this feature, but well Qt is too big to use it in every project.

like image 248
user1873947 Avatar asked Dec 06 '25 08:12

user1873947


1 Answers

According to Boost documentation (checked in 1.48.0), the necessary template specialisations for std::shared_ptr and std::weak_ptr already exist in Boost, so std smart pointers should be usable out of the box with signals2 (via slot::track_foreign).

like image 87
Angew is no longer proud of SO Avatar answered Dec 07 '25 21:12

Angew is no longer proud of SO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!