shared_ptrs with std::mem_fn

Hi, I've converted a container to use shared_ptrs instead of regular pointers, now my for_each algorithm doesn't work: Before: class Attr; std::vector< Attr* > mAttributes; . . . std::for_each( mAttributes.begin(), mAttributes.end(), std::bind2nd( std::mem_fn( &Attr::Write ), output ) ); After: std::vector< shared_ptr<Attr> > mAttributes; Now it doesn't compile because (of course) Attr::Write is not a method of shared_ptr<Attr>. Do I have to use boost's bind and mem_fn objects instead of std? Thanks for any help. -- Regards, Steve.

Steve Folly
Hi,
I've converted a container to use shared_ptrs instead of regular pointers, now my for_each algorithm doesn't work:
Before:
class Attr;
std::vector< Attr* > mAttributes; . . . std::for_each( mAttributes.begin(), mAttributes.end(), std::bind2nd( std::mem_fn( &Attr::Write ), output ) );
After:
std::vector< shared_ptr<Attr> > mAttributes;
Now it doesn't compile because (of course) Attr::Write is not a method of shared_ptr<Attr>.
Do I have to use boost's bind and mem_fn objects instead of std?
Yes; bind and mem_fn handle this problem (and quite a few others) automatically. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

I'm reading from an xml archive (the impl provided) into an object of the wrong class ( a sibling class with common abstract base class ) I catch archive_exception = 7 ( i/o error on stream). what() returns "unknown derived exception" (incidentally) At this point, enough of the archive has been read (namely a message header) to allow me to know the correct class of the archived object (!). So, now I create an object of the correct class and attempt to unserialize it using the same archive. This results in abort(). My questions are: can I safely recover and read the archive again after an exception, given that I have the archive and the istream object it was created with? in general, can you read an archive more than once? does it rewind itself automatically after a successful read? Thanks, Russell Balest p.s. i'm not really planning to use this technique, just experimenting.
participants (3)
-
David Abrahams
-
Russell Balest
-
Steve Folly