Checking that a template parameter is an enum
Nordlöw via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 1 15:41:19 PDT 2015
On Thursday, 1 October 2015 at 22:37:57 UTC, Ali Çehreli wrote:
> Very quickly:
>
> import std.traits;
>
> template allSame(V...)
> if (isExpressions!(V))
> {
> bool impl_(V...)() {
> static if (V.length > 1) {
> foreach (i, _; V[0 .. $ - 1]) {
> if (V[i] != V[i + 1]) {
> return false;
> }
> }
>
> return true;
>
> } else {
> return true;
> }
> }
>
> enum allSame = impl_!V();
> }
Will this spare memory in DMD? If so there are a few traits that
should be update accordingly, for instance `allSatisfy` and
`anySatisfy`.
Thanks!
More information about the Digitalmars-d-learn
mailing list