title: How and why one would use Boost signals2?
body: <p>Learning c++ and trying to get familiar with some patterns. The <a href="http://www.boost.org/doc/libs/1_54_0/doc/html/signals2/tutorial.html#idp164790912" rel="noreferrer">signals2 doc</a> clearly has a vast array of things I can do with slots and signals. What I don't understand is what types of applications (use cases) I should use it for. </p>
  
  <p>I'm thinking along the lines of a state machine dispatching change events. Coming from a dynamically typed background (C#,Java etc) you'd use an event dispatcher or a static ref or a callback. </p>
  
  <p>Are there difficulties in c++ with using cross-class callbacks? Is that essentially <em>why</em> signals2 exists? </p>
  
  <p>One to the example cases is a document/view. How is this pattern better suited than say, using a vector of functions and calling each one in a loop, or say a lambda that calls state changes in registered listening class instances? </p>
  
  <pre><code>class Document
  {
  public:
      typedef boost::signals2::signal&lt;void ()&gt;  signal_t;
  
  public:
      Document()
      {}
  
      /* Connect a slot to the signal which will be emitted whenever
        text is appended to the document. */
      boost::signals2::connection connect(const signal_t::slot_type &amp;subscriber)
      {
          return m_sig.connect(subscriber);
      }
  
      void append(const char* s)
      {
          m_text += s;
          m_sig();
      }
  
      const std::string&amp; getText() const
      {
          return m_text;
      }
  
  private:
      signal_t    m_sig;
      std::string m_text;
  };
  </code></pre>
  
  <p>and </p>
  
  <pre><code>class TextView
  {
  public:
      TextView(Document&amp; doc): m_document(doc)
      {
          m_connection = m_document.connect(boost::bind(&amp;TextView::refresh, this));
      }
  
      ~TextView()
      {
          m_connection.disconnect();
      }
  
      void refresh() const
      {
          std::cout &lt;&lt; "TextView: " &lt;&lt; m_document.getText() &lt;&lt; std::endl;
      }
  private:
      Document&amp;               m_document;
      boost::signals2::connection  m_connection;
  };
  </code></pre>