Making recursively-defined traits iterative using `static foreach`

Nordlöw per.nordlow at gmail.com
Sat Mar 10 19:39:13 UTC 2018


On Saturday, 10 March 2018 at 18:26:48 UTC, Simen Kjærås wrote:
>> Is there a way to break the `static foreach` loop prematurely 
>> as quickly as `allSameTypeIterative` becomes false?
>
> Sure:
>
> @property
> bool allSameTypeIterative(V...)()
> //if (allSatisfy!(isType, V))
> {
>     foreach (Vi; V)
>         if (Vi != V[0]) return false;
>     return true;
> }
>
> No, it's not quite the same, but it's easier to read and gives 
> the same result.
>
> --
>   Simen

That will trigger CTFE, but I'm trying to avoid that.


More information about the Digitalmars-d mailing list