Let's suppose I am writing a function template GCD
which uses both operator/
and operator%
. For some types, for example, complex numbers or polynomials both can be computed efficiently (i.e. when dividing polynomials you get remainder "for free"). So some of my class templates have divmod
implemented, which returns a pair of quotient and remainder.
However some classes and notably built-in types, such as int
, do not have divmod
(or equivalent) implemented. If I was about to write one GCD
which uses divmod
I would discriminate against the other types (and vice versa). I haven't been able to come up with a template specialization which wouldn't require most of the code for GCD
to be repeated.
What are my options here?