I'm trying to create new objects and add them to a list of objects using boost::bind. For example.
struct Stuff {int some_member;};
struct Object{
Object(int n);
};
....
list<Stuff> a;
list<Object> objs;
....
transform(a.begin(),a.end(),back_inserter(objs),
boost::bind(Object,
boost::bind(&Stuff::some_member,_1)
)
);
This doesn't appear to work. Is there any way to use a constructor with boost::bind, or should I try some other method?
If you are using boost 1.43, you can use boost::factory and boost::value_factory, which let you encapsulate a constructor invocation. Like this:
transform(a.begin(),a.end(),back_inserter(objs),
boost::bind(boost::value_factory<Object>(),
boost::bind(&Stuff::some_member,_1)
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With