The amazing template which does nothing

Max Samukha via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 28 15:24:51 PDT 2015


On Tuesday, 28 April 2015 at 02:36:38 UTC, Vladimir Panteleev 
wrote:
> http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/

A truly polymorphic identity function in D would be more involved:

template id(a...) if (a.length == 1)
{
     static if (__traits(compiles, { alias id = a[0]; } ))
         alias id = a[0];
     else
         enum id = a[0];
}

static assert(is(id!int == int));
static assert(id!1 == 1);

Also, an 'isEqual' template would be needed to unify 'isSame', 
'is' and '=='.


More information about the Digitalmars-d mailing list