Currently 3 different dynamic casts are needed to access a residual from the vector of stages (for example, to set a reference): - [x] Casting the CostAbstract held by a stage to a CostStack object - [x] Casting the component to a composite cost (usually QuadraticResidualCost) - [x] Casting the underlying residual We could define template functions (eg: getComponent<T> and getResidual<T>) to access the residual more easily.