diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-05 15:36:09 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-05 15:36:09 +0100 |
commit | 5d5892dbbf42deb4eb4c6e9b85befb0d7a59f1f3 (patch) | |
tree | af732510347759a9223c9dba70706fab4d2e1d1a /include/value.h | |
parent | af85b7133413a861c52260b1c0c7ffb4c841e950 (diff) |
updated documentation about functions, introducted += operator with a Php::Value on the right side, and an integral variable on the left
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 */ } |