Why shared_ptr used in solver factory?
The SolverFactory::get
and SolverFactory::getPreconditioner
and the utility method getSolverFromFactory
all return the result by shared_ptr
. Why? A factory should mostly return a unique_ptr
, or to cite Herb Sutter GitW #90:
Guideline: A factory that produces a reference type should return a
unique_ptr
by default, or ashared_ptr
if ownership is to be shared with the factory.
The issue with shared_ptr
is, that 1. creation, copy, and destruction costs something, 2. a shared_ptr
cannot be converted into a unqiue_ptr
, but vice versa is fine.
Maybe second part of the guideline applies here? Do I miss something?