Is old style compile-time foreach redundant?

Stefan Koch uplink.coder at googlemail.com
Sun Jan 7 00:55:27 UTC 2018


On Saturday, 6 January 2018 at 23:25:58 UTC, Ali Çehreli wrote:
> Is 'static foreach' sufficient for all needs or is there any 
> value for regular foreach over compile-time sequences?
>
> Code unrelated to the question:
>
> import std.stdio;
>
> void main() {
>     // Old style compile-time foreach. This still works
>     // when 'static' is uncommented below.
>     import std.meta : AliasSeq;
>     /* static */ foreach (i; AliasSeq!(1, "hello", 2)) {
>         writeln(i);
>     }
>
>     // Proper 'static foreach'.
>     import std.range : iota;
>     import std.algorithm : map;
>     static foreach (i; 3.iota.map!(a => a * 10)) {
>         writeln(i);
>     }
> }
>
> Ali

No it's not.
When you can use the old style do so. Since it puts less stress 
on the compiler in the general case.


More information about the Digitalmars-d-learn mailing list