From 4f034b4d03841c568b21cf1a26a29aa9b3e33375 Mon Sep 17 00:00:00 2001 From: zwimer Date: Mon, 10 Oct 2022 15:36:13 -0700 Subject: [PATCH 1/3] Fix --- documentation/index.rst | 1 + documentation/limitations.rst | 92 +++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 documentation/limitations.rst diff --git a/documentation/index.rst b/documentation/index.rst index b017d276..ab5543c1 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -15,6 +15,7 @@ Contents: install basics config + limitations examples debugging testing diff --git a/documentation/limitations.rst b/documentation/limitations.rst new file mode 100644 index 00000000..ef2e7d94 --- /dev/null +++ b/documentation/limitations.rst @@ -0,0 +1,92 @@ +Binder Limitations +################## + +This section lists some of ``binder``'s more prominent limitations. + +------------------ +External Operators +------------------ + +Unlike C++, which allows operators to be defined outside of classes and redefined across different namespaces, python requires operators be member functions and thus lacks the ability to choose which overload to use based on context. +In line with this, ``binder`` will only bind (most) C++ operators if they are member functions (i.e. they cannot be defined externally). + +These operators include, but are not necessarily limited to: + +.. code-block:: console + + operator+ (__add__) + operator- (__sub__) + operator* (__mul__) + operator/ (__div__) + + operator+ (__iadd__) + operator- (__isub__) + operator* (__imul__) + operator/ (__idiv__) + + operator() (__call__) + operator== (__eq__) + operator!= (__ne__) + operator[] (__getitem__) + operator= (assign) + operator++ (plus_plus) + operator-- (minus_minus) + +----------------- +Ignored Operators +----------------- + +The following operators will be ignored by binder: + +.. code-block:: console + + // Arithmetic + % + %= + + // Bitwise + ~ + & + | + ^ + << + >> + + &= + |= + ^= + <<= + >>= + + // Logical + && + || + + // Cast to T + explicit operator T() + operator T() + + // Misc + , + new + new[] + delete + delete[] + +------------- +Miscellaneous +------------- + +1. The pre/post increment operators both map to ``plus_plus`, with the pre-increment operator being invoked via ``a.plus_plus()`` and post-increment via ``.plus_plus(0)``; just as the operators are technically defined in C++. The same is true for the pre/post decrement operators, both called ``minus_minus``. + +2. User defined literals ``operator"" _foo`` end up being named as ``operator_foo``. + +---------- +Known Bugs +---------- + +1. The unary ``operator+`` and unary ``operator-`` currently map to ``__add__`` and ``__sub__`` rather than ``__pos__`` and ``__neg__``. + +2. The unary ``operator*`` (dereference operator) will currently map to ``__mul__``. + +3. In ``C++``, if a user defines ``std::ostream& operator<<`` in a namespace distinct from the class definition, it is possible the autogenerated code might not be compilable as it will generate a ``__str__`` function which will use the ``<<`` operator without properly specifing which namespace the operator is in. From d92895f455d664ef877624509b3df52e3f7a91a4 Mon Sep 17 00:00:00 2001 From: zwimer Date: Mon, 10 Oct 2022 15:37:44 -0700 Subject: [PATCH 2/3] Fix + mod support update --- documentation/limitations.rst | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/documentation/limitations.rst b/documentation/limitations.rst index ef2e7d94..bb3fc80f 100644 --- a/documentation/limitations.rst +++ b/documentation/limitations.rst @@ -18,11 +18,13 @@ These operators include, but are not necessarily limited to: operator- (__sub__) operator* (__mul__) operator/ (__div__) + operator% (__mod__) - operator+ (__iadd__) - operator- (__isub__) - operator* (__imul__) - operator/ (__idiv__) + operator+= (__iadd__) + operator-= (__isub__) + operator*= (__imul__) + operator/= (__idiv__) + operator%= (__imod__) operator() (__call__) operator== (__eq__) @@ -40,10 +42,6 @@ The following operators will be ignored by binder: .. code-block:: console - // Arithmetic - % - %= - // Bitwise ~ & From 6baa38736eafb5ce2532ee4a81142e076fad5c83 Mon Sep 17 00:00:00 2001 From: zwimer Date: Mon, 10 Oct 2022 16:05:35 -0700 Subject: [PATCH 3/3] Update to reflect recent updates in master --- documentation/limitations.rst | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/documentation/limitations.rst b/documentation/limitations.rst index bb3fc80f..f9125461 100644 --- a/documentation/limitations.rst +++ b/documentation/limitations.rst @@ -13,6 +13,7 @@ In line with this, ``binder`` will only bind (most) C++ operators if they are me These operators include, but are not necessarily limited to: .. code-block:: console + operator~ (__invert__) operator+ (__add__) operator- (__sub__) @@ -20,12 +21,24 @@ These operators include, but are not necessarily limited to: operator/ (__div__) operator% (__mod__) + operator& (__and__) + operator| (__or__) + operator^ (__xor__) + operator<< (__lshift__) + operator>> (__rshift__) + operator+= (__iadd__) operator-= (__isub__) operator*= (__imul__) operator/= (__idiv__) operator%= (__imod__) + operator&= (__iand__) + operator|= (__ior__) + operator^= (__ixor__) + operator<<= (__ilshift__) + operator>>= (__irshift__) + operator() (__call__) operator== (__eq__) operator!= (__ne__) @@ -42,20 +55,6 @@ The following operators will be ignored by binder: .. code-block:: console - // Bitwise - ~ - & - | - ^ - << - >> - - &= - |= - ^= - <<= - >>= - // Logical && || @@ -86,5 +85,3 @@ Known Bugs 1. The unary ``operator+`` and unary ``operator-`` currently map to ``__add__`` and ``__sub__`` rather than ``__pos__`` and ``__neg__``. 2. The unary ``operator*`` (dereference operator) will currently map to ``__mul__``. - -3. In ``C++``, if a user defines ``std::ostream& operator<<`` in a namespace distinct from the class definition, it is possible the autogenerated code might not be compilable as it will generate a ``__str__`` function which will use the ``<<`` operator without properly specifing which namespace the operator is in.