opBinary : Static ifs or specialization?
claptrap
clap at trap.com
Wed Jun 24 09:01:28 UTC 2020
On Wednesday, 24 June 2020 at 00:53:58 UTC, H. S. Teoh wrote:
> On Tue, Jun 23, 2020 at 11:53:36PM +0000, claptrap via
>>
>
> If your implementations are based on built-in operators, you
> could use mixins to unify the implementations into one, e.g.:
Ah yeah thats useful, to expand a bit what about if the RHS is a
different type?
Point!T opBinary(string op, RHS)(RHS rhs)
{
static if (is(RHS == Point!float) || is(RHS == Point!double))
{
// .. etc..
}
else static if (is(RHS == float) || is(RHS == double))
{
// etc...
}
else static if (is(RHS == float[2]) || is(RHS == double[2]))
{
// .. etc...
}
assert(0); // type not supported
}
should that be split up?
More information about the Digitalmars-d-learn
mailing list