How to make copied boost :: signal?

I understand why it boost::signalcannot be copied (because copying the signal does not have a clear meaning), but I need its version, which provides some copy of ctor (either no-op, or copies all connections).

The reason why I need this is because in my project many objects become not copyable only due to the presence of signals and for processing them with convenient value semantics (shared_ptrs are not so convenient) I need to manually provide copy-ctors, violating DRY Obviously, such a quasi-copied signal would be a good workaround for C ++ ugliness.

The first solution that comes to mind inherits signaland provides a copy of ctor in a derived class, but this does not mean that the signal does not have a virtual dtor.

Thoughts?

+3
source share
6 answers

Try holding pointers (or shared_ptr) to singles instead of signals.

+7
source

I would go for the internal inputs in shared_ptr. This way your objects will be directly copied, and you can use the semantics of the values.

+3
source

. , - . , , , , boost:: signal .

namespace Iraimbilanja {

// the copy constructor doesn't copy the signal, so it doesn't copy the connections...
struct EmptyOnCopySignal
{
private:
    boost::shared_ptr<boost::signal> _signal;
};

// the copy constructor references the same signal, so it copies the connections...
struct CopyableSignal
{
private:
    boost::shared_ptr<boost::signal> _signal;
};

} // namespace Iraimbilanja
+2

- ? - , . , , -, , , / . ?

, Decorator.

+1

boost:: ref. . boost, . , , , , .

+1

Holding the signal inside shared_ptr (by default) will cause the signal to be shared by all copied objects. Running a signal in one object will cause each slot connected to the signal to be notified of all copies. This may not be the behavior you want.

If you do not want this to happen, you could write your own copy constructor and copy operator, then you can specify what you want when your objects are copied.

+1
source

Source: https://habr.com/ru/post/1704292/


All Articles