D's greatest mistakes

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Nov 29 04:31:42 PST 2010


On 11/29/10, bearophile <bearophileHUGS at lycos.com> wrote:
>> * Template pattern matching is incomplete
>
> I don't understand this, please explain better. But I think the syntax of
> is() is awful and I'd like to shoot it.
>

+1. I'd prefer if we had a constraint block of some kind. I mean we
already have in/out contracts which look very nice:

void somefunc()
in
{
    // ...contract preconditions...
}
out (result)
{
    // ...contract postconditions...
}
body
{
    // ...code...
}

Why not do the same for templates? Something like this:

void foo(A, B, C)(A a, B b, C c)
constraint
{
    isDynamicArray(a);
    isIterable(a);
}
body
{
    ...
}

So maybe every statement would be checked for the return value, and
you would get the exact line where a constraint failed when
instantiating a template.

Just a passing thought anyway..


More information about the Digitalmars-d mailing list