What's wrong with D's templates?

Max Samukha spambox at d-coding.com
Tue Dec 22 02:57:18 PST 2009


On 22.12.2009 5:15, Walter Bright wrote:
> Yigal Chripun wrote:
>> But that doesn't mean the idea itself isn't valid. Perhaps a different
>> language with different goals in mind can provide a much simpler non
>> convoluted implementation and semantics for the same idea?
>> You've shown in the past that you're willing to break backward
>> compatibility in the name of progress and experiment with new ideas.
>> You can make decisions that the C++ committee will never approve.
>>
>> Doesn't that mean that this is at least worth a shot?
>
> I believe that D's template constraint feature fills the bill, it does
> everything Concepts purported to do, and more, in a simple and easily
> explained manner, except check the template body against the constraint.

...and template overloading based on concept refinement. D requires 
hacks to accomplish that:

template isFoo(T)
{
}

template isBar(T)
{
     enum isBar = ... && isFoo!T;
}

template Foo(T) if (isFoo!T && !isBar!T /+ hack +/) {}
template Foo(T) if (isBar!T) {}

In the run-time domain, it would be analogous to requiring a parameter 
to specify which interfaces the argument *should not* implement:

interface IFoo
{
}

interface IBar : IFoo
{
}

void foo (IBar a)
{
}

void foo ((IFoo && !IBar) a) // meh
{
}

Maybe it is not a significant shortcoming but it needs to be mentioned.

>
> The latter is, in my not-so-humble opinion, a desirable feature but its
> desirability is overwhelmed by the payment in complexity and
> constrictions on the Concepts necessary to make it work.



More information about the Digitalmars-d mailing list