@@ -371,8 +371,14 @@ struct signal_emit<void, void, T_arg...>
371
371
372
372
} /* namespace internal */
373
373
374
+ // TODO: When we can break ABI, let signal_base instead of signal_with_accumulator
375
+ // derive from trackable, as in sigc++2. One of them must derive from trackable.
376
+ // Otherwise the slot returned from signal_with_accumulator::make_slot() is not
377
+ // automatically disconnected when the signal is deleted.
378
+ // https://github.com/libsigcplusplus/libsigcplusplus/issues/80
379
+
374
380
/* * Signal declaration.
375
- * signal_with_accumulator can be used to connect() slots that are invoked
381
+ * % signal_with_accumulator can be used to connect() slots that are invoked
376
382
* during subsequent calls to emit(). Any functor or slot
377
383
* can be passed into connect(). It is converted into a slot
378
384
* implicitly.
@@ -396,7 +402,9 @@ struct signal_emit<void, void, T_arg...>
396
402
* @ingroup signal
397
403
*/
398
404
template <typename T_return, typename T_accumulator, typename ... T_arg>
399
- class signal_with_accumulator : public signal_base
405
+ class signal_with_accumulator
406
+ : public signal_base
407
+ , public trackable
400
408
{
401
409
public:
402
410
using slot_type = slot<T_return(T_arg...)>;
@@ -461,11 +469,6 @@ class signal_with_accumulator : public signal_base
461
469
}
462
470
463
471
/* * Creates a functor that calls emit() on this signal.
464
- *
465
- * @note %sigc::signal does not derive from sigc::trackable in sigc++3.
466
- * If you connect the returned functor (calling %emit() on signal1) to
467
- * another signal (signal2) and then delete signal1, you must manually
468
- * disconnect signal1 from signal2 before you delete signal1.
469
472
*
470
473
* @code
471
474
* sigc::mem_fun(mysignal, &sigc::signal_with_accumulator::emit)
@@ -485,19 +488,28 @@ class signal_with_accumulator : public signal_base
485
488
486
489
signal_with_accumulator () = default ;
487
490
488
- signal_with_accumulator (const signal_with_accumulator& src) : signal_base(src) {}
491
+ signal_with_accumulator (const signal_with_accumulator& src) : signal_base(src), trackable(src) {}
489
492
490
- signal_with_accumulator (signal_with_accumulator&& src) : signal_base(std::move(src)) {}
493
+ signal_with_accumulator (signal_with_accumulator&& src)
494
+ : signal_base(std::move(src)), trackable(std::move(src))
495
+ {
496
+ }
491
497
492
498
signal_with_accumulator& operator =(const signal_with_accumulator& src)
493
499
{
494
500
signal_base::operator =(src);
501
+ // Don't call trackable::operator=(src).
502
+ // It calls notify_callbacks(). This signal is not destroyed.
495
503
return *this ;
496
504
}
497
505
498
506
signal_with_accumulator& operator =(signal_with_accumulator&& src)
499
507
{
500
508
signal_base::operator =(std::move (src));
509
+ if (src.impl_ != impl_)
510
+ src.notify_callbacks ();
511
+ // Don't call trackable::operator=(std::move(src)).
512
+ // It calls notify_callbacks(). This signal is not destroyed.
501
513
return *this ;
502
514
}
503
515
};
@@ -531,7 +543,7 @@ class signal_with_accumulator : public signal_base
531
543
* @par Example:
532
544
* @code
533
545
* void foo(int) {}
534
- * sigc::signal<void, long> sig;
546
+ * sigc::signal<void( long) > sig;
535
547
* sig.connect(sigc::ptr_fun(&foo));
536
548
* sig.emit(19);
537
549
* @endcode
0 commit comments