The amazing template which does nothing
Dicebot via Digitalmars-d
digitalmars-d at puremagic.com
Tue Apr 28 16:08:14 PDT 2015
On Tuesday, 28 April 2015 at 22:24:53 UTC, Max Samukha wrote:
> 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 '=='.
Actually I do find more specialized names/implementations useful
in this case. For example, just the fact that you use
`unaryFun!(a => a)` instead of `Identity!(a => a)` makes code
more readable and intention clear even if effect is the same.
More information about the Digitalmars-d
mailing list