1

It is possible to exclude class methods in CPPYY based on their function arguments?

For example, suppose that a class has two constructors:

class A
{
 A(int);
 A(double);
};

Is it possible to select class A but exclude one of the two constructors?

Selecting and excluding classes/methods is done using the genreflex utility, which uses an XML file to configure CPPYY. But it's not clear if that the XML file supports this level of specification.

Bill Hart
  • 359
  • 2
  • 15

1 Answers1

1

Posting here as well for completeness:

No, no such feature exist. (It’s part of the lcgdict spec to exclude a method wholesale, but I don’t think that that’s even implemented.)

If you want to reduce the ctors to just 1, that’s quick & easy in Python. Example:

import cppyy

cppyy.cppdef("""
class A
{
public:
 A(int) { std::cerr << "int called" << std::endl; }
 A(double) { std::cerr << "double called" << std::endl; }
};
""")

def pythonize_A(klass, name):
    if name == 'A':
        klass.__init__ = klass.__init__.__overload__("int")

cppyy.py.add_pythonization(pythonize_A)

from cppyy.gbl import A

a = A(1)
b = A(1.) # <- fails with TypeError

and in principle you could even write a custom __init__ that does overloading on the constructors that you do want to preserve (e.g. a simple loop over a subset selected using __overload__).

Alternatively, you can use cross-inheritance to achieve the same.

Wim Lavrijsen
  • 3,453
  • 1
  • 9
  • 21