[bind] bind and back_inserter
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
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
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
Thanks, I knew it was easy. ;-) But at least it's in the mailing list, now, for reference.
participants (2)
-
Christian Henning
-
Jeff F