On Friday, 19 May 2017 at 17:47:42 UTC, Stefan Koch wrote:
On Friday, 19 May 2017 at 17:34:28 UTC, Dominikus Dittes Scherkl wrote:
On Friday, 19 May 2017 at 00:14:05 UTC, Stefan Koch wrote:

string enumToString(E)(E v)
{
    static assert(is(E == enum),
        "emumToString is only meant for enums");

Why that assert? We can check it at compiletime. Doesn't this cry for a constraint? I would use asserts only ever for stuff that's only known at runtime.

string enumToString(E)(E v) if(is(E == enum))
{
   ...
}

the static assert tells what's going on.
It it does result in a simple overload not found.

Hm. Maybe in this case it's ok, because enum is pretty much all that can be expected as argument to "enumToString". But normally I would calling not using a constraint "stealing overload possibilities", because it would not be possible to overload the same function for a different type if you use this kind of assert.
And the error message is not really better.

Reply via email to