templates
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 17 13:44:00 PDT 2014
ddos:
> one possible solution would be a static if, like this:
>
> TVector opBinary(string op)(TVector rhs)
> {
> static if(n == 4)
> {
> // fast impl for n==4
> }
> else
> {
> // old impl
> }
> }
>
> but i'd like to avoid this since it makes the code very ugly to
> read
>
> any suggestions :) ?
You can add a template constraint and write two functions:
TVector opBinary(string op)(TVector rhs) if(n == 4) {...
TVector opBinary(string op)(TVector rhs) if(n != 4) {...}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list