[sigc] How does std::function<> work with libsigc++



C+11 has std::function<> which is a bit like sigc::slot, though C++11
doesn't have anything like sigc::signal<>. I played with that here:
http://www.murrayc.com/permalink/2013/07/08/c-in-glom-shared_ptr-and-slotsfunctions/

I've noticed that std::function<> works with libsigc++, as in the code
below, but I wonder why it works. Can anyone explain?


#include <iostream>
#include <string>
#include <sigc++/sigc++.h>
#include <functional>

void on_print(const std::string& str)
{
  std::cout << str;
}

int main()
{
  sigc::signal<void, const std::string&> signal_print;
  
  std::function<void(const std::string&)> slot = &on_print;
  signal_print.connect(slot);
  
  signal_print.emit("hello world\n");

  return 0;
}

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]