[Boost-bugs] [Boost C++ Libraries] #12483: signals2 bind to member function by value fail to signal when using trackable

Subject: [Boost-bugs] [Boost C++ Libraries] #12483: signals2 bind to member function by value fail to signal when using trackable
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-09-26 13:03:57


#12483: signals2 bind to member function by value fail to signal when using
trackable
-------------------------------------+----------------------------
 Reporter: kim.lykke.johansen@… | Owner: dgregor
     Type: Support Requests | Status: new
Milestone: To Be Determined | Component: signals
  Version: Boost 1.61.0 | Severity: Not Applicable
 Keywords: signals2 trackable bind |
-------------------------------------+----------------------------
 In my trail to learn and get comfortable with signals2 I wrote a small
 test program.
 In this program I encountered what I believe to be inconsistency in the
 way that signals2 connect to member functions when using bind, when using
 trackable aswell.
 {{{
 #!div style="font-size: 80%"
 Test program:
   {{{#!c++
 #include "boost/signals2.hpp"
 #include <iostream>


 class SignalTest : public boost::signals2::trackable
 {
 public:
         SignalTest() {};

         void printInfo(const std::string name, int num)
         {
                 std::cout << "Signal: " << name << " " << num <<
 std::endl;
         }
 };

 int main()
 {
         boost::signals2::signal<void (const std::string&, int)> sig;

         SignalTest test1;
         sig.connect(boost::bind(&SignalTest::printInfo, test1, _1, _2));
         sig("Test", 1);

         {
                 SignalTest test2;
                 sig.connect(boost::bind(&SignalTest::printInfo, test2, _1,
 _2));
                 sig("Test", 2);
         }

         return 0;
 }
   }}}
 }}}

 The code above compiles and running it I'd expect both signals to be
 printed, however nothing is printed.
 If however I bind the signalTest object "test2" by reference like the code
 below:
 {{{
 #!div style="font-size: 80%"
 Bind by reference:
   {{{#!c++
 sig.connect(boost::bind(&SignalTest::printInfo, &test2, _1, _2));
   }}}
 }}}
 The following is printed:
 {{{
 #!div style="font-size: 80%"
 test2 bind by reference print
   {{{#!text
 Signal: Test 2
   }}}
 }}}

 And if I also bind signalTest object "test1" by reference the following is
 printed:
 {{{
 #!div style="font-size: 80%"
 test1 and test2 bind by reference print
   {{{#!text
 Signal: Test 1
 Signal: Test 2
 Signal: Test 2
   }}}
 }}}


 As I was lead to understand from the example code of section "Automatic
 Connection Management" in the tutorial at
 http://www.boost.org/doc/libs/1_61_0/doc/html/signals2/tutorial.html#idp394616720
 I should be able to call the member function by value, however this is not
 the case using trackable.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12483>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC