shared_ptr and lazy copy
Is there an easier way to use shared_ptr as a lazy copy method? It seems to me that the only way to do it would be by testing unique() (or use_count()) every time the pointed-to object was to be changed: boost::shared_ptr<foo> bar(new foo); boost::shared_ptr<foo> baz = bar; if(!baz->unique()) ... // make a deep copy baz->ChangeAFoo(); I can't think of a good way to alter shared_ptr either. The only thing I came up with would be const and non-const versions of operator-> and operator* where the non-const versions checked unique() and made a deep copy. This would seem to fall into that last question in the FAQ anyway... "Why doesn't shared_ptr provide (your pet feature here)". I'd think this could easily lead to unnecessary deep copies unless the programmer took explicit steps (lots of const_cast's) to avoid it. Am I missing anything? --Mark Storer Software Engineer Cardiff Software #include <disclaimer> typedef std::disclaimer<Cardiff> Discard;
participants (1)
-
Mark Storer