RFC: Value range propagation for if-else
via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 23 02:21:31 PDT 2014
On Sunday, 22 June 2014 at 21:10:31 UTC, bearophile wrote:
> Nordlöw:
>
>> auto pow(T)(T arg, uint n)
>> {
>> enum vr = __traits(valueRange, arg);
>> static if (vr.min == vr.max) // if arg is constant
>
> I think that unfortunately this currently can't work, you can't
> tell the range of the input value like that. I have explained
> why in one of my posts in this thread. Please try to explain me
> why I'm wrong.
Don't know what you're referring to, but I guess you mean that -
because of separate compilation - the code generated for `pow`
needs to be generic? This is not really a problem, because the
compiler can generate _additional_ specialized functions for it.
But then, a normal `if` would also do, because dead code
elimination can remove the unused parts in these specializations.
More information about the Digitalmars-d
mailing list