Concepts? Template specialization depending on class functions?

Sean Kelly sean at f4.ca
Fri Mar 3 10:01:36 PST 2006


Ben Phillips wrote:
> In article <du7qud$2ji7$1 at digitaldaemon.com>, Sean Kelly says...
>> Coupled with Don's template string magic, it should be fairly simple to 
>> improve the error message to include the supplied type name, etc.
>>
>> So... while I think concepts may still be nice to have, I'm not sure 
>> there's a pressing need for them any longer.  In fact, I think I'm going 
>> to go back and rewrite my template code to use the "static if" method 
>> above, as most of it still uses the old C++ style.
> 
> While this is true, if you have a large interface to check for compatability
> with, template code can still 
> become messy.

Yup.  I briefly considered private functions with aliases inside the 
static if:

private implA() {}
private implB() {}

template conceptFn( T ) {
     static if( /* supports A */ )
         alias implA conceptFn;
     else if( /* supports B */ )
         alias implB conceptFn;
     else
     {   pragma( msg, "Not supported." );
         static assert( false );
     }
}

But I ultimately decided to simply format and comment things in a way 
that was as readable as possible.


Sean



More information about the Digitalmars-d mailing list