May 19, 2017
On Friday, 19 May 2017 at 20:23:16 UTC, Dominikus Dittes Scherkl wrote:
> 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:
>>> [...]
>>
>> 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.

You can still overload :)
D has SFINAE
May 19, 2017
On Friday, May 19, 2017 8:31:52 PM PDT Stefan Koch via Digitalmars-d wrote:
> On Friday, 19 May 2017 at 20:23:16 UTC, Dominikus Dittes Scherkl
>
> wrote:
> > 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:
> >>> [...]
> >>
> >> 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.
>
> You can still overload :)
> D has SFINAE

Wait, what? Doesn't D specifically _not_ have SFINAE? You can use static if to test what compiles, and the branch whose condition compiles is then the on that gets compiled in, which kind of emulates what you'd get with SFINAE, but that's not really the same as SFINAE, which just outright picks the the template specialization which happens to compile while letting the others that don't compile not generate errors. D complains when you have multiple, matching templates. So, what do you mean that D has SFINAE?

- Jonathan M Davis

May 19, 2017
On Friday, 19 May 2017 at 21:01:09 UTC, Jonathan M Davis wrote:

>
> Wait, what? Doesn't D specifically _not_ have SFINAE? You can use static if to test what compiles, and the branch whose condition compiles is then the on that gets compiled in, which kind of emulates what you'd get with SFINAE, but that's not really the same as SFINAE, which just outright picks the the template specialization which happens to compile while letting the others that don't compile not generate errors. D complains when you have multiple, matching templates. So, what do you mean that D has SFINAE?
>
> - Jonathan M Davis

If a template does trigger a static assert,
that static assert is ignored if there is another template in the overload set that could match.

May 19, 2017
On Friday, 19 May 2017 at 21:04:24 UTC, Stefan Koch wrote:

> If a template does trigger a static assert,
> that static assert is ignored if there is another template in the overload set that could match.

Wow. Didn't know that.
Is this really part of the D grammar?
Sometimes D is soo cool.

Still - too cool for me to see this. I don't like templates looking similar and even taking the same types but the compiler does something too intelligent to avoid an ambiguity.

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.
May 19, 2017
On Friday, 19 May 2017 at 21:23:11 UTC, Dominikus Dittes Scherkl wrote:
> On Friday, 19 May 2017 at 21:04:24 UTC, Stefan Koch wrote:
>
>> If a template does trigger a static assert,
>> that static assert is ignored if there is another template in the overload set that could match.
>
> Wow. Didn't know that.
> Is this really part of the D grammar?
> Sometimes D is soo cool.
>
> Still - too cool for me to see this. I don't like templates looking similar and even taking the same types but the compiler does something too intelligent to avoid an ambiguity.
>
> 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.
May 19, 2017
On Friday, 19 May 2017 at 21:23:11 UTC, Dominikus Dittes Scherkl wrote:
> On Friday, 19 May 2017 at 21:04:24 UTC, Stefan Koch wrote:
>
>> If a template does trigger a static assert,
>> that static assert is ignored if there is another template in the overload set that could match.
>
> Wow. Didn't know that.
> Is this really part of the D grammar?

No, no need to. This is not related to the grammar but to the semantic.


May 20, 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?

May 19, 2017
On Friday, May 19, 2017 9:04:24 PM PDT Stefan Koch via Digitalmars-d wrote:
> On Friday, 19 May 2017 at 21:01:09 UTC, Jonathan M Davis wrote:
> > Wait, what? Doesn't D specifically _not_ have SFINAE? You can use static if to test what compiles, and the branch whose condition compiles is then the on that gets compiled in, which kind of emulates what you'd get with SFINAE, but that's not really the same as SFINAE, which just outright picks the the template specialization which happens to compile while letting the others that don't compile not generate errors. D complains when you have multiple, matching templates. So, what do you mean that D has SFINAE?
> >
> > - Jonathan M Davis
>
> If a template does trigger a static assert,
> that static assert is ignored if there is another template in the
> overload set that could match.

Why on earth would it work that way? It sounds like a bug to me.

- Jonathan M Davis

1 2
Next ›   Last »