#include <sigc++/sigc++.h>
#include <glibmm/refptr.h>
#include <iostream>
#include <memory>


class Test
{
public:
   Test()
      : mRefCount(1)
   {
      std::cout << "Constructed Test" << std::endl;
   }

   ~Test()
   {
      std::cout << "Destroying Test" << std::endl;
   }

   void reference()
   {
      ++mRefCount;
   }

   void unreference()
   {
      --mRefCount;
      if (mRefCount == 0) {
         delete this;
      }
   }

private:
   int mRefCount;

   // Non-copyable.
   Test(const Test&);
   Test& operator=(const Test&);
};


static void f(Glib::RefPtr<Test> p)
{
}


int main(int argc, char* argv[])
{
   typedef sigc::slot<void> VoidSlot;

   std::auto_ptr<VoidSlot> slotPtr(new VoidSlot());

   {
      Glib::RefPtr<Test> p(new Test());
      *slotPtr = sigc::bind(sigc::ptr_fun(&f), p);
   }

   std::cout << "Disconnecting slot..." << std::endl;
   slotPtr->disconnect();
   std::cout << "Disconnected slot" << std::endl;

   std::cout << "Reassigning slot..." << std::endl;
   *slotPtr = VoidSlot();
   std::cout << "Reassigned slot" << std::endl;

   std::cout << "Destroying slot..." << std::endl;
   slotPtr.reset();
   std::cout << "Destroyed slot" << std::endl;

   return 0;
}
