Is old style compile-time foreach redundant?

Ali Çehreli acehreli at yahoo.com
Sat Jan 6 23:25:58 UTC 2018


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



More information about the Digitalmars-d-learn mailing list