Boost logo

Boost Users :

From: Jeff F (TriumphSprint2000_at_[hidden])
Date: 2007-04-11 14:50:34


Christian,

See in line below:

Christian Henning wrote:
> I cannot figure out how to copy a vector to another vector and calling
> a member function. Please consider the following example.
>
> #include <string>
> #include <vector>
> #include <algorithm>
> #include <functional>
>
> #include <boost/bind.hpp>
>
> using namespace std;
> using namespace boost;
>
> class A
> {
> public:
> A( const string& name ) : _name( name ) {}
> const string& name() const { return _name; }
>
> private:
> string _name;
> };
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> vector<A> as;
> as.push_back( A( "A" ));
> as.push_back( A( "B" ));
>
>
> vector<string> ss;
>
> // how to call A::name for each A????
> copy( as.begin()
> , as.end()
> , back_inserter( ss ));

   transform( as.begin()
            , as.end()
            , back_inserter( ss )
            , bind( &A::name, _1 )
            );

> return 0;
> }
>
> I'm sure it's very easy, but I don't see right now.

Jeff Flinn


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