Type-specific overloads in Phobos

Dmitry Olshansky dmitry.olsh at gmail.com
Sun Nov 3 01:18:46 PST 2013


03-Nov-2013 13:07, Joseph Rushton Wakeling пишет:
> Hello all,
>
> There are various generic functions in Phobos that can benefit from
> type-specific overloads.  For example, in std.math and std.numeric,
> functions that deal with integers may benefit from having specialized
> implementations to work with BigInt.
>
> Question: what's the appropriate location for these overloads?  In the
> same module as their type,

Yes, it's the only path that scales.

> or in the same module as the function they're
> overloading?

Hardly scales - by the end of day they shouldn't be all imported by 
std.math. Plus it's BigInt business to do some dirty internal work to 
speed up common algorithms.

> What are the implications for correct inferring of what
> function to use, or useful aliases (e.g. alias abs = std.math.abs)?

Technically as long as the types are different there is no hijacking 
going on (w/o aliases). The moment you add an alias it's as if you 
declare it in your module, so it would fail to match on BigInt because 
of anti-hijacking.

//this should work though:
alias abs = std.math.abs;
alias abs = std.bigint.abs;

> Thanks & best wishes,
>
>      -- Joe


-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list