Output parameters in PyROOT

This registers bar in the global ROOT module, so I would only be able to call it once.

I think in this case I can however try with

ROOT.gInterpreter.Declare('''
    std::pair<std::unique_ptr<Bar>, std::unique_ptr<Baz>> foo_adapter() {
        Bar* bar;
        Baz* baz;
        
        foo(&bar, &baz);
        
        return {std::unique_ptr<Bar>(bar), std::unique_ptr<Baz>(baz)};
    }
''')

bar_in_py, baz_in_py = ROOT.foo_adapter()

bar_in_py.bar_method()
baz_in_py.baz_method()

This works (thanks!) but is it correct w.r.t. ownership? The outputs of this function (bar_in_py and baz_in_py) should be managed by python (e.g., the pointed objects should be deleted when bar_in_py and baz_in_py are garbage collected).

How would I do instead if foo was a method? Is it possible to attach the adapter function to the same class with a pythonization?