boost-signals2

Why does enable_shared_from_this lack direct access to the embedded weak_ptr?

徘徊边缘 提交于 2019-12-06 14:22:13
I want to use boost signals2 with automatic connection management in a multithreaded application. My class inherits from enable_shared_from_this<> and i want to connect a member method from within another member method. The connection might be rebuilt frequently so my code should be as fast as possible (despite from the boost signals2 performance itself): typedef boost::signals2::signal<void ()> signal_type; struct Cat : public enable_shared_from_this<Cat> { void meow (); void connect (signal_type& s) { // can't write this s.connect (signal_type::slot_type (&Cat::meow, this, _1).track (weak

Force deletion of slot in boost::signals2

ⅰ亾dé卋堺 提交于 2019-12-03 12:55:29
问题 I have found that boost::signals2 uses sort of a lazy deletion of connected slots, which makes it difficult to use connections as something that manages lifetimes of objects. I am looking for a way to force slots to be deleted directly when disconnected. Any ideas on how to work around the problem by designing my code differently are also appreciated! This is my scenario: I have a Command class responsible for doing something that takes time asynchronously, looking something like this

Force deletion of slot in boost::signals2

回眸只為那壹抹淺笑 提交于 2019-12-03 02:26:40
I have found that boost::signals2 uses sort of a lazy deletion of connected slots, which makes it difficult to use connections as something that manages lifetimes of objects. I am looking for a way to force slots to be deleted directly when disconnected. Any ideas on how to work around the problem by designing my code differently are also appreciated! This is my scenario: I have a Command class responsible for doing something that takes time asynchronously, looking something like this (simplified): class ActualWorker { public: boost::signals2<void ()> OnWorkComplete; }; class Command : boost:

Boost::signals2 - descruction of an object with the slot

南楼画角 提交于 2019-12-01 23:39:49
Consider this: #include <boost/signals2.hpp> #include <iostream> struct object_with_slot { void operator()() { std::cout << "Slot called!" << std::endl; member = 50500; } int member; }; int main() { boost::signals2::signal<void ()> sig; object_with_slot * ptr = new object_with_slot; sig.connect(*ptr); delete ptr; sig(); } Output is "Slot called!" and no crash or anything. That's why I have a few questions: 1) Why there is no crash? 2) Why there is no crash even if the slot function assigns something to object which doesn't exist? 3) How can I make the signal automatically track the lifetime of

Does the boost.signals2 library need to be built?

老子叫甜甜 提交于 2019-12-01 00:46:53
My system is having trouble building the boost libraries. I understand that most boost libraries are (fortunately) just headers that do not need to be build (with some exceptions). Does the boost :: signals2 library need to be built? Also is the boost.signals2 library dependant on the boost.signals library? Signals is not header-only, signals2 is. But however, signals2 is explicitly developed for thread-safety and if you use boost.thread, this has to be compiled. As far as I know signals2 is not dependent on signals headers. No, signals2 is header only. See here . 来源: https://stackoverflow.com

How and why one would use Boost signals2?

我的未来我决定 提交于 2019-11-29 22:25:44
Learning c++ and trying to get familiar with some patterns. The signals2 doc clearly has a vast array of things I can do with slots and signals. What I don't understand is what types of applications (use cases) I should use it for. I'm thinking along the lines of a state machine dispatching change events. Coming from a dynamically typed background (C#,Java etc) you'd use an event dispatcher or a static ref or a callback. Are there difficulties in c++ with using cross-class callbacks? Is that essentially why signals2 exists? One to the example cases is a document/view. How is this pattern

How and why one would use Boost signals2?

牧云@^-^@ 提交于 2019-11-27 10:50:06
问题 Learning c++ and trying to get familiar with some patterns. The signals2 doc clearly has a vast array of things I can do with slots and signals. What I don't understand is what types of applications (use cases) I should use it for. I'm thinking along the lines of a state machine dispatching change events. Coming from a dynamically typed background (C#,Java etc) you'd use an event dispatcher or a static ref or a callback. Are there difficulties in c++ with using cross-class callbacks? Is that