digitalmars.D.learn - Unary operators for Variants
- Jeff (9/9) Mar 09 2021 So, I can't seem to get unary operators to work with variants.
- Imperatorn (3/12) Mar 10 2021 Try jsvar
So, I can't seem to get unary operators to work with variants. For example: Variant x = 10; writeln(-x); // Error: x is not of arithmetic type, it is a VariantN!32LU Obviously binary operators like + work fine. Is there a reason opUnary wasn't implemented as well? Is there a work-around for me to implement it myself outside of the VariantN class? Thanks!
Mar 09 2021
On Tuesday, 9 March 2021 at 20:05:07 UTC, Jeff wrote:So, I can't seem to get unary operators to work with variants. For example: Variant x = 10; writeln(-x); // Error: x is not of arithmetic type, it is a VariantN!32LU Obviously binary operators like + work fine. Is there a reason opUnary wasn't implemented as well? Is there a work-around for me to implement it myself outside of the VariantN class? Thanks!Try jsvar https://dpldocs.info/experimental-docs/arsd.jsvar.html
Mar 10 2021