Boost logo

Boost :

From: Johan Torp (johan.torp_at_[hidden])
Date: 2007-05-23 09:07:04


Why are the connect/disconnect methods in boost::signals not
const-qualified? You want to abstract away who and how many is
listening, don't you? I think it would be natural if these were const
methods and emitting a signal required non-const access.

This would allow me to write code like this:

class SomeLogicClass
{
public:
  const signal<void()>& GetSomeEventSignal() const;
};

In this case, only SomeLogicClass itself can emit signals but anyone
can listen to the signal.

Today I need to add a wrapper method (see below), which preferably is
either templated - to accept any functor - or uses boost::function.
The first option requires me to have the implementation and include
<boost/signal.hpp> in the header file. The second option adds a
dependency to boost::function. Both of these thunks or trampoline
functions can be avoided if connect/disconnect was consted.

// Option 1
class SomeLogicClass
{
public:
  template<class Slot> boost::signals::connection
  ConnectToEventSignal(const Slot& slot) const { ... }
};

// Option 2
class SomeLogicClass
{
public:
  boost::signals::connection ConnectToEventSignal(const
boost::function<void()>& slot) const;
};

Best Regards, Johan Torp


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk