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
  • templates ddos via Digitalmars-d-learn
    • Re: templates bearophile via Digitalmars-d-learn

Reply via email to