
Question 11: Smart pointers in C++ [6]
======================================

Some implementations of the C++ "memory" library support unique_ptr
 in addition to shared_ptr.

The distinguishing feature of unique_ptr is that it cannot be
shared/copied - the original can be the only pointer to the item,
and the only permissible operation is to "move" it from one unique
pointer to another (through an std::move operation).  (Note this
also applies to passing the unique_ptr as a value parameter, a call
to std::move is required for the pass).

The distinguishing implementation detail is that, because they are the
unique pointer to an item, no reference counts are needed/used - they
simply deallocate the item when they are done with it.

Suggest and discuss examples of where unique pointers would be appropriate and why,
and examples of where shared pointers would be more appropriate and why.


Solution outline -- still mostly abbreviated point form, should be expanded on
----------------

Unique pointers might be crucial where we have

   - exception handling related to an object (unique control
     over error handling/processing)

   - threading (strict control over a resource)

   - one central controller object??

Shared pointers

   - anywhere where multiple objects want to share control over
     an item (they all need access, they all need to be able to
     alter item)

Based on absence of reference counts, improved performance from
   unique pointers ... maybe they're better in general if the object
   doesn't need to be shared??

Based on the extra "move" requirement to pass unique pointers as
   value parameters, maybe passing shared_ptrs makes more sense
   if we do a lot of by-value parameter passing?

Based on the notion that "some implementations" support unique_ptrs,
   there's an implication that some do not ... clearly if we want to
   be compatible with those implementations of C++, we pretty much
   have to use shared_ptr

