title: Expose a non-const but noncopyable member in Boost Python
body: <p>Here's my problem:</p>
  
  <p>I have two classes like these:</p>
  
  <pre class="lang-c prettyprint-override"><code>class Signal {
  public:
      void connect(...) { sig.connect(...); }
  private:
      boost::signal2::signal sig;
  };
  
  class MyClass {
  public:
      Signal on_event;
  };
  </code></pre>
  
  <p>I would like to expose <code>MyClass::on_event</code> so that I can call <code>my_class_instance.on_event.connect(...)</code> from Python.</p>
  
  <p>This is how I've wrapped those classes:</p>
  
  <pre class="lang-c prettyprint-override"><code>class_&lt;Signal, boost::noncopyable&gt; ("Signal", noinit)
      .def("connect", &amp;some_helper_function);
  
  class_&lt;MyClass&gt; ("MyClass")
      .def_readonly("on_event", &amp;MyClass::on_event);
  </code></pre>
  
  <p>This compiles, but when I try to call <code>connect</code> from Python I get: <code>AttributeError: can't set attribute</code>. This is explained here: <a href="http://www.boost.org/doc/libs/1_53_0/libs/python/doc/tutorial/doc/html/python/exposing.html" rel="nofollow">http://www.boost.org/doc/libs/1_53_0/libs/python/doc/tutorial/doc/html/python/exposing.html</a>, so I changed to <code>.def_readwrite</code> for <code>on_event</code>.</p>
  
  <p>But now I get a compile time error instead. Its an almost impossible to read C++ template error message, but as far as I understand it its because <code>boost::signals2::signal</code> is noncopyable. Since <code>.def_readwrite</code> makes the member assignable it must not be noncopyable. But for my usage I don't want to assign the member, I just wan't to call one method.</p>
  
  <p>I thought about making the <code>connect</code> method of <code>Signal</code> const, even though it alters the object, but then I couldn't call <code>sig.connect()</code> from that method, so that was a no go as well..</p>
  
  <p>Any ideas?</p>