Boost logo

Boost :

From: Jody Hagins (jody-boost-011304_at_[hidden])
Date: 2004-11-24 23:19:05

On Wed, 24 Nov 2004 11:57:55 -0500
Doug Gregor <dgregor_at_[hidden]> wrote:

> On Nov 24, 2004, at 9:31 AM, Jody Hagins wrote:
> > In any event, how do you suggest I "replace" a conected slot, while
> > still guaranteeing that the "connection" is invoked exactly once?
> Oh, yuck. This is something the signals interface just can't handle...
> suggestions are welcome.

OK, I made a brief attempt. Diffs (diff -rc) are attached if you want
to take a look...


1. added template typed_connection, which inherits from connection, so
that a connection object can know the type of the signal (and ultimately
the slot). This new class has a replace_slot() method that will replace
the slot of the connection.

2. added a free function signals::detail::replace_slot() which mucks
around with the internals and swaps out the slot in the connection with
a new slot.

3. changed the return type of connect() to be the exact connection type.
 This should remain backward compatible since the return type used to be

Here is a simple example...

#include "boost/signals.hpp"
#include "boost/bind.hpp"
#include <iostream>

struct slot
      boost::signal<void (char const *)> & sig)
    : conn_(sig.connect(boost::bind(&slot::one, this, _1)))
  void one(char const * s) const
    std::cout << "one()(" << s << ")\n";
    conn_.replace_slot(boost::bind(&slot::two, this, _1));
  void two(char const * s) const
    std::cout << "two()(" << s << ")\n";
  operator bool() const { return conn_.connected(); }
  boost::signal<void (char const *)>::connection_type conn_;

int main(
    int argc,
    char * argv[])
  boost::signal<void (char const *)> sig;
  for (int i = 1; i < argc; ++i)
    slot s(sig);
    while (s)

Boost list run by bdawes at, gregod at, cpdaniel at, john at