[Semi-OT] to!string(enumType)

Dominikus Dittes Scherkl via Digitalmars-d digitalmars-d at puremagic.com
Fri May 19 17:14:23 PDT 2017


On Friday, 19 May 2017 at 21:25:22 UTC, Stefan Koch wrote:
> On Friday, 19 May 2017 at 21:23:11 UTC, Dominikus Dittes 
> Scherkl wrote:
>> And it's not visible from the API or documentation - you need 
>> to look into the source to disambiguate - I'm not convinced 
>> and still consider this bad style.
>
> If they take exactly the same parameters the compiler will flag 
> an error.
> But if the parameters are merely compatible you can use static 
> assert, to shoot things out of the overload set.

Hm. To keep with your example:

string enumToString(E)(E v)
{
    static assert(is(E == enum), ... );
}

if I want to overload it with, lets say

string enumToString(T)(T n) if(isNumeric!T)
{
}

that looks very much like "exactly the same parameters", yes?
SO it won't compile - you have stolen the overload possibility.

What kind of "merely compatible" parameters do you have in mind, 
that would make your static assert pattern useful?



More information about the Digitalmars-d mailing list