Skip to content

Passing Smart Pointers Reference Sheet

The following is based on CppCon 2014: Herb Sutter “Back to the Basics! Essentials of Modern C++ Style”

unique_ptr<Widget> factory() // source: produces Widget
void sink(unique_ptr<Widget>) // sink - consumes widget, takes ownership
void reseat(unique_ptr<Widget>&) // "will" or "might" reseat ptr (replace Widget)
void thinko(const unique_ptr<Widget>&) // Use const& instead\
shared_ptr<Widget> factory() // source + shared ownership
void share(shared_ptr<Widget>) // share - "will" retain refcount
void reseat(shared_ptr<Widget>&) // "Will" or "might" reseat ptr
void may_share(const shared_ptr<Widget>&) // "Might" retain refcount
unique_ptr<Widget>& get_intance() // Weird and no reason. A singleton can be a regular reference.

See also: