You can safely store the underlying pointer in a stack variable, so long as the shared pointer does not get destroyed or re-assigned in the meantime. That could make the code a bit simpler to read.