Partial specialisation: howto? (in the right news group this time. *sigh*)

div0 div0 at users.sourceforge.net
Sun May 17 01:39:14 PDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks Simen,

That's nicer than the chained static ifs.
Is there anyway to get rid of the enum though?

Using the enum is a pain as it means you have to edit that import
anytime you need to create a specialistion.

Simen Kjaeraas wrote:
> div0 wrote:
> 
> It seems I might know how to do this after all.
> 
> As is mentioned under template constraints[1], templates can be
> specialized by trailing the parameter list with a condition:
> 
> template createHandlerCode( T... ) if ( T[0]._type ==
> EHandlerType.eMsgRangeHdlr ) {
>  string format( ) {
>    return createMessageRangeHandler!( T ).format();
>  }
> }
> template createHandlerCode( T... ) if ( T[0]._type ==
> EHandlerType.eMsgHdlr ) {
>  string format( ) {
>    return createMessageHandler!( T ).format();
>  }
> }
> template createHandlerCode( T... ) if ( T[0]._type ==
> EHandlerType.eCmdIdHdlr ) {
>  string format( ) {
>    return createCommandIdHandler!( T ).format();
>  }
> }
> 
> This code is D2-only and untested, so there is certainly a possibility
> it will not work for you.
> 
> [1]: http://www.digitalmars.com/d/2.0/template.html#Constraint
> 
> -- 
>  Simen


- --
My enormous talent is exceeded only by my outrageous laziness.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFKD80yT9LetA9XoXwRAjwYAJ94ZdQT/+UP6iTP/Vgplf2M02zpXgCfSYpD
GgdBnsafroFNvffhEFqeuVY=
=Wbhe
-----END PGP SIGNATURE-----


More information about the Digitalmars-d-learn mailing list