Trust Eric Niebler to deliver

Copy constructor semantics

As the name indicates, use unique_ptr when there must exist exactly one owner to a resource. The copy constructor of unique_ptr is disabled, which means it is impossible for two instances of it to exist. However, it is movable... Which is fine, since that allows transfer of ownership.

Also as the name indicates, shared_ptr represents shared ownership of a resource. However, there is also another difference between the two smart pointers: The Deleter of a unique_ptr is part of its type signature, but it is not part of the type signature of shared_ptr. That is because shared_ptr uses "type erasure" to "erase the type" of the deleter. Also note that shared_ptr can also be moved to transfer ownership (like unique_ptr.)

When should I use move semantics?

Although shared_ptr can be copied, you may want to move them anyways when you are making a transfer of ownership (as opposed to creating a new reference). You're obligated to use move semantics for unique_ptr, since ownership must be unique.

When should I use copy semantics?

In the case of smart pointers, you should use copying to increase the reference count of shared_ptrs. (If you're unfamiliar with the concept of a reference count, research reference counted garbage collection.)

Should I ever use both?

Yes. As mentioned above, shared_ptr can be both copied and moved. Copying denotes incrementing the reference count, while moving only indicates a transfer of ownership (the reference count stays the same.)

See also:
  • Iq option http://www.iqoption.com.vn Vietnam
Yifangya Makis Bens Case for iPhone 5/5S BralnStructufeAmdFunctien Bmc Neuroscience Full Text Symbiotic Relationship Between Bimonthly Journals
Wireless (Yifangya)
  • Quality pictures printed onto the back of cover case.
  • Custom molded to the shape of your Apple iPhone 5/5S.
  • Strong durable plastic with light weight.
  • Constructed from high quality materials.
  • Protects your phone from scratches and accidental bumps.
Related Posts