GotW #90 Solution: Factories -- Herb Sutter
The solution to the latest GotW problem is now available:
GotW #90 Solution: Factories (updated for C++11/14)
by Herb Sutter
From the article:
Guideline: A factory that produces a reference type should return aunique_ptr
by default, or ashared_ptr
if ownership is to be shared with the factory.Guideline: A factory that produces a non-reference type should return a value by default, and throw an exception if it fails to create the object. If not creating the object can be a normal result, return an
optional<>
value.