Checking that a template parameter is an enum

Per Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 2 05:43:07 PDT 2015


On Thursday, 1 October 2015 at 22:37:57 UTC, Ali Çehreli wrote:
> 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 proposed `static foreach` reduce number of instantiations 
here?


More information about the Digitalmars-d-learn mailing list