Template constraints in D

Dee Girl deegirl at noreply.com
Sat Jun 21 16:42:27 PDT 2008


Walter Bright Wrote:

> You're the first I've heard say that Concepts have a natural syntax! But 
> let me try:
> 
> template Stack(T)
> {
>      const Stack =
>          __traits(compiles,
> 	    (T t)
> 	    {	T.value_type v = top(t);
> 		push(t, v);
> 		pop(t);
> 		if (empty(t)){}
> 	    });
> }
> 
> The idea is that the desired operations are expressed as operations, 
> rather than as function signatures.

I think is much easier another way.

void stackConcept(T)()
{
    T t;
    T.value_type v = top(t);
    push(t, v);
    pop(t);
    if (empty(t)){}
}

You simply call is(typeof(stackConcept!(T))) after. It is Very easy.

> > An unrelated comment is that I don't think it is relevant or respectful 
> > to compare the lengths of the specs.  The spec for Concepts that you 
> > link to includes many many more in depth examples than the D spec does. 
> >  It's an apples vs oranges comparison.  So 5 pages vs 49 pages really 
> > doesn't have much meaning at all.
> 
> I wished to make the point that D constraints build on what one already 
> knows - how to write a D expression. Concepts, on the other hand, have a 
> major new syntax and semantic thing that must be learned. Perhaps I 
> expressed the point badly, do you have a suggestion?

I hope this is not offensive. I said one that you focus on comparing D with C++ to much. And again you do the same with concepts. Comparison by any body else that you is ok. But if you do comparison is terrible. Makes you look second in run trying to reach first. You are not loser and do not want to look like loser. I study kyokushin karate 9 year. I was not good ^_^ but it was good for me. Sensei said many times best karate ka not compete with others. He compete with himself. Best fighter wants to do his best not only better than others. I understood him after years. I hope I express myself ok.

One thing is also you implemented functionality in C++ concepts. Implementation is clever. But you do not bring original thing. You do what the C++ documentation does. Nothing else. It is not creative and not original. D is not C++ monkey. Stop looking at C++, do what you know is good; and you will be happy. Sorry, Dee Girl




More information about the Digitalmars-d mailing list