Skip to content

User-defined conversion operators overloads (typecasts) #326

@lczech

Description

@lczech

Hey @lyskov,

quick question: The Limitations of Binder mention that type casting operators operator T() are ignored. Looking at the implementation in Binder for operator overloads though, it seems thought that at least some common type conversions might be possible, by mapping for instance __bool__, __int__, __float__, __complex__, __str__ to their respective C++ equivalents? Unless I'm missing something, adding those to the map in Binder's cpp_python_operator might just already out of the box, or not?

Of course, custom types would not be supported, but I think at least for those common ones, it might make sense!

Edit: For __str__, there is already an overload in Binder when an operator << is defined for a class, so that might conflict. On the other hand, it seems that Binder does not generate any code that uses __repr__, so maybe that can be used for the operator << instead? Or just kept as overloads in Python as well, if that works?

Let me know what you think, and thanks
Lucas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions