Now that's a DIP that could use some love

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Fri Sep 18 16:02:50 UTC 2020


On Friday, 18 September 2020 at 15:43:44 UTC, Meta wrote:
> enum string failConstraint(string name, string msg, Args...) = 
> `alias %s = AliasSeq!(false, %s)`.format(Args[0], 
> processArgs!(Args[1..$])); //processArgs is a helper template 
> that converts types to string, etc...
>
> template isInputRange(R)
> {
>     static if (!is(typeof(R.init) RInit == R))
>         mixin(failConstraint!(isInputRange, `%s.init must have 
> type %s, but it has type %s`, R, R, RInit);
>     else static if (!is(ReturnType!((R r) => r.empty) REmpty == 
> bool))
>         mixin(failConstraint!(isInputRange, `ReturnType!((%s r) 
> => r.empty) must be of type bool, but it is %s`, R, REmpty);
>     else static if (...)
>         ...etc.
>     else
>         enum isInputRange = true;
> }

Why not return a struct that has result of test and message for 
it (was mentioned before, in original discussion about multiple 
if constraints)?

It can also be improved to aggregate multiple error messages from 
different tests inside a template like isInputRange!T.

Regards,
Alexandru.


More information about the Digitalmars-d mailing list