PyROOT and templated C++ member functions

Hi all,

I have another question where I’m not sure if it is a bug or a feature. this time regarding access to template member functions in PyROOT. According to my understanding it should be possible to call those using something like

obj.member("template arguments as C++ type")("arguments")

However this only works after accessing the attribute first on the class object. Otherwise trying to access the member results in an AttributeError. So I have to do

ROOT.MyClass.templateMember

foo = MyClass()
foo.templateMember("std::string")("bar")

It looks like a bug in the attribute lookup but it’s not clear to me if this is maybe somehow intentional and I’m just using it wrong.

Cheers,

Martin

PS: full example: templatemember.py (544 Bytes)


ROOT Version: 6.14/04
Platform: Ubuntu 16.04
Compiler: GCC 8.2, Python 3.6.6


Hi Martin,
Thanks for reporting, I will need to investigate it but indeed it looks like a bug.

Templated classes do work, though:

ROOT.gInterpreter.Declare("""
template<class T>
struct TestClass {
    void testMember(const T& value) {
        std::cout << "Argument: " << value << std::endl;
    }
};
""")

t = ROOT.TestClass("std::string")()
t.testMember("foo")

Hi,

Some more information.

This actually does not work either in the experimental PyROOT with modern Cppyy. I checked the template tests of Cppyy and I found this, which makes it possible that these tests work - they are similar to yours. So cppyy needs that extra non-templated sibling to work, because of some bug in genreflex (according to the comment).

@Axel do you know what this genreflex bug that Wim mentions here is about?

Enric

Now being followed here:
https://sft.its.cern.ch/jira/browse/ROOT-9789

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.