Since you are returning `x`, you have to use `const Ptr<RCP<const Basic>> &x` and `outArg` in the caller, see:

https://github.com/sympy/csympy/blob/master/doc/style_guide.md#passing-tofrom-functions

I am surprised that your version works --- I am just following the recommendations from Teuchos::RCP documents (linked from here: https://github.com/sympy/csympy/blob/master/doc/design.md). I think there are some reason against the way you did it.