Solving a constraint hiding an error in a function literal

Salih Dincer salihdb at hotmail.com
Fri Feb 3 14:00:33 UTC 2023


On Friday, 3 February 2023 at 12:43:54 UTC, Nick Treleaven wrote:
> 
> The new trait can be used as a constraint or as a `static if` 
> condition. As a constraint it can help to determine which 
> overload matches. Imagine two overloads:
> ```d
> // body would call a(int)
> void f(alias a)()
> if (__traits(callable, a, int()))
>
> // body would call a(int, int)
> void f(alias a)()
> if (__traits(callable, a, int(), int()))

I prefer to use `static if` inside the template to avoid similar 
situations. Otherwise, I have a difficult process to find where 
the error is.

SDB at 79


More information about the Digitalmars-d mailing list