Boost logo

Boost Users :

From: Maitre Bart (maitrebart_at_[hidden])
Date: 2006-11-10 17:11:25


Maitre Bart <maitrebart <at> excite.com> writes:

Typos corrected:

I have this:

  typedef LegacySequentialContainer<string> LegacyStringVector;

  LegacyStringVector lsv;

  // ... filling lsv with strings ...

I realized this:

  boost::counting_iterator<int> it(0);
  boost::counting_iterator<int> end(lsv.length());
  while (it < end)
    cout << boost::bind(&LegacyStringVector::operator[], lsv, _1)(*it++)
<< " ";
  cout << "\n";

and it works. However, I wish to do the same but using std::copy or
std::for_each instead.

I tried the following but none is able to compile:

  copy(boost::counting_iterator<int>(0),
       boost::counting_iterator<int>(lsv.size()),
       boost::bind(ostream_iterator<string>(cout, " "),
                   &vector<string>::operator[],
                   lsv,
                   _1));

  copy(boost::counting_iterator<int>(0),
       boost::counting_iterator<int>(lsv.size()),
       boost::bind(ostream_iterator<string>(cout, " "),
                   boost::bind<string,int>(&vector<string>::operator[], lsv,
_1)));
 
  copy(boost::counting_iterator<int>(0),
       boost::counting_iterator<int>(lsv.size()),
       boost::bind(ostream_iterator<string>(cout, " "),
                   boost::bind<string,int>(&vector<string>::operator[], lsv),
                   _1));

I must be close to the solution but error messages do not help guiding me in
the right direction.

Anyone has any suggestion?
 


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