Click here to Skip to main content
15,903,030 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have an application that is relying heavily on boost signals2. One issue that I want to address is that I do not want objects to be able to register a member function to a signal twice. Is there a mechanism to enforce that?

Looking at the tutorial, I don't really see this kind of enforcement documented.

http://www.boost.org/doc/libs/1_40_0/doc/html/signals2/tutorial.html

What I want is something like:

class HelloWorld
{
  public:
    HelloWorld()
    {
       this->_signal.connect(boost::bind(&HelloWorld::Hello, this)); // Connects
       this->_signal.connect(boost::bind(&HelloWorld::Hello, this)); // Desired: Does NOT Connect again.
       this->_signal.connect(boost::bind(&HelloWorld::World, this)); // Connects
       this->_signal.connect(boost::bind(&HelloWorld::World, this)); // Desired: Does NOT Connect again.
    }

    void operator()() const
    {
       this->_signal();
    }

    void Hello()
    {
      std::cout << "Hello ";
    }

    void World()
    {
      std::cout << "World!";
    }

  private:
    boost::signals2::signal<void> _signal;
};

// Desired Output: "Hello World!"</void>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900