January 18, 2006
Currently, to specialize on a concept, something like the following must be done:

template isDog( T ) {
    const bit isDog = is(T:Scottie) || is(T:Daschund);

template walkAnimal( T, bit check : true = isDog!( T ) ) {
    walkAnimal( T animal ) {
        // make sure the user didn't try to trick me
        static assert( isDog!( T ) );


template walkAnimal( T, bit check : false ) {
    walkAnimal( T animal ) {
        // make sure the user didn't try to trick me
        static assert( !isDog!( T ) );


This is a bit awkward for simple cases and can easily become quite complex.  Also, it is unappealing that the concept checking currently must be done via template parameters, which can be overridden by the clever user.  C++ 0x will support concepts in some form both to aid in error reporting and to simplify trait-based specialization, and it would be tremendously useful for D to have something similar.  Also, I think D is already is very good shape for supporting this, as static if, is, etc, provide an existing, straightforward means to switch on type attributes.

The C++ proposals are outlined in various forms here:


The key concept in each proposal is a 'where' clause that is separated from the list of template parameters.  I won't pretend to know how this would best fit into the D syntax however.

Top | Discussion index | About this forum | D home