Boost logo

Boost Users :

From: Seweryn Habdank-Wojewódzki (shw_at_[hidden])
Date: 2007-08-26 15:38:42


Dears

I have question.

Why there are problems to connect function that returns auto_ptr to the
signal? Below there is a code which won't compile i line where is comment.

Regards.

#include <iostream>
#include <boost/signals.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <memory>
#include <vector>
#include <iterator>
#include <algorithm>

class some_class {
public:
  ::std::vector <int> func1() {
    using ::std::vector;
    typedef vector <int> Res;

    Res res (2);
    res.at(0) = 13;
    res.at(1) = 14;
    return res;
  }

  ::boost::shared_ptr < ::std::vector <int> > func2() {
    using ::std::vector;
    using ::boost::shared_ptr;
    typedef shared_ptr < vector <int> > Res;

    Res res (new vector<int> (2));
    res->at(0) = 23;
   res->at(1) = 24;
    return res;
  }

  ::std::auto_ptr < ::std::vector <int> > func3() {
    using ::std::vector;
    using ::std::auto_ptr;
    typedef auto_ptr < vector <int> > Res;

    Res res (new vector<int> (2));
    res->at(0) = 33;
    res->at(1) = 34;
    return res;
  }
};

int main()
{
  using ::boost::signal;
  using ::std::vector;
  using ::std::auto_ptr;
  using ::boost::shared_ptr;
  using ::boost::bind;

  some_class sc;

  signal < vector <int> (void) > sig1;
  signal < shared_ptr < vector <int> > (void) > sig2;
  signal < auto_ptr < vector <int> > (void) > sig3;

  sig1.connect (bind (&some_class::func1,&sc));
  vector <int> ret1 (sig1());

  ::std::copy (ret1.begin(), ret1.end(),
    ::std::ostream_iterator<int> (::std::cout, "\n"));

  sig2.connect (bind (&some_class::func2,&sc));
  vector <int> ret2 (*sig2());

  ::std::copy (ret2.begin(), ret2.end(),
    ::std::ostream_iterator<int> (::std::cout, "\n"));

  sig3.connect (bind (&some_class::func3,&sc));
  //sig3(); // <- ERROR

}

-- 
|\/\/|   Seweryn Habdank-Wojewódzki
 \/\/

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net