diff options
Diffstat (limited to 'include/value.h')
-rw-r--r-- | include/value.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/value.h b/include/value.h index d0079dc..b732616 100644 --- a/include/value.h +++ b/include/value.h @@ -684,6 +684,24 @@ protected: std::ostream &operator<<(std::ostream &stream, const Value &value); /** + * Custom +=, -=, *=, /=, &= operators, to update integral types with a Php::Value + * + * This code looks complicated, it ensures that the operators are only + * overloaded for integral types (int, bool, etc) - and not for complex types + * (arrays, objects, etc) + */ +template <typename X, typename std::enable_if<std::is_integral<X>::value>::type* = nullptr> +X &operator+=(X &x, const Php::Value &value) { return x += (X)value; } +template <typename X, typename std::enable_if<std::is_integral<X>::value>::type* = nullptr> +X &operator-=(X &x, const Php::Value &value) { return x -= (X)value; } +template <typename X, typename std::enable_if<std::is_integral<X>::value>::type* = nullptr> +X &operator*=(X &x, const Php::Value &value) { return x *= (X)value; } +template <typename X, typename std::enable_if<std::is_integral<X>::value>::type* = nullptr> +X &operator/=(X &x, const Php::Value &value) { return x /= (X)value; } +template <typename X, typename std::enable_if<std::is_integral<X>::value>::type* = nullptr> +X &operator%=(X &x, const Php::Value &value) { return x %= (X)value; } + +/** * End of namespace */ } |