Using multiple mixin templates to implement operator overloading
    Tobias Pankrath 
    tobias+dlang at pankrath.net
       
    Sat Dec 12 17:36:57 UTC 2020
    
    
  
I want to wrap e.g. an int and implement basic arithmetic. In the 
provided example [1] I use  two mixin templates to separately 
implement scaling (multiplication with int/double) and addition 
and subtraction with the type itself.
In the end I want to have several distinct wrappers and allow 
specific operations between them and int / double. It's important 
that the return values are typed correctly, otherwise I could use 
std.typecons.Proxy.
My problem is that both overloads of opBinary work, but not at 
the same time. As soon as I mixin both templates, they stop to 
work. If I just paste the implementation into the body of 
WrapInt, they work both at the same time though.
Could someone explain the mechanics behind it?
Thanks!
[1] https://run.dlang.io/is/WbG987
    
    
More information about the Digitalmars-d-learn
mailing list