Skip to content

Commit 705a73a

Browse files
committed
added +,- operators so user can do -a and bitwise inplace operators;
1 parent 69d22a4 commit 705a73a

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

include/pythonic/pythonicVars.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,6 +4092,44 @@ namespace pythonic
40924092
}
40934093
throw pythonic::PythonicTypeError("operator^ requires integral types or sets/lists");
40944094
}
4095+
// In-place bitwise AND
4096+
var &operator&=(const var &other) {
4097+
*this = *this & other;
4098+
return *this;
4099+
}
4100+
4101+
// In-place bitwise OR
4102+
var &operator|=(const var &other) {
4103+
*this = *this | other;
4104+
return *this;
4105+
}
4106+
4107+
// In-place bitwise XOR
4108+
var &operator^=(const var &other) {
4109+
*this = *this ^ other;
4110+
return *this;
4111+
}
4112+
4113+
// In-place bitwise AND with primitive
4114+
template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
4115+
var &operator&=(T other) {
4116+
*this = *this & var(other);
4117+
return *this;
4118+
}
4119+
4120+
// In-place bitwise OR with primitive
4121+
template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
4122+
var &operator|=(T other) {
4123+
*this = *this | var(other);
4124+
return *this;
4125+
}
4126+
4127+
// In-place bitwise XOR with primitive
4128+
template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
4129+
var &operator^=(T other) {
4130+
*this = *this ^ var(other);
4131+
return *this;
4132+
}
40954133

40964134
// Bool conversion
40974135
operator bool() const

0 commit comments

Comments
 (0)