Template constraints in D

janderson askme at me.com
Sat Jun 21 18:37:49 PDT 2008


Walter Bright wrote:
 >
 > (Also comparing them with C++0x concepts.)
 >
 > http://www.digitalmars.com/d/2.0/cpp0x.html#concepts
 >
 > http://www.digitalmars.com/d/2.0/concepts.html
 >
 > Essentially, I think we cover the necessary ground with an order of 
magnitude simpler system.

As I understand it, one thing C++0x concepts will be able to do is 
resolve collisions/overloading in a reasonable way.  Can someone can 
inherit from say isAddable and then write a specialized template for that?

Furthermore is there a way to specialize something like:

template Foo(T, int N)
     if (isAddable!(T) && isprime(N))

Once someone has already written that in another lib and you want to add 
something like:

template Foo(T, int N)
     if (isAddable!(T) && isprime(N) && isLessThen(N, 100))

Can the compiler figure out which to use?  Maybe it could in this case, 
but in more complex example what would it choose?

One way that would be possible is to write a new template with a 
different name that calls Foo.  However that's not ideal because then 
you can't optimize (for instance) places where Foo is already in use.

-Joel



More information about the Digitalmars-d mailing list