Palindromes
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 3 23:46:33 PST 2015
On 12/03/2015 04:23 PM, Jim Barnett wrote:
> The `import` statement inside the `for`-loop kind of smells to me.
In addition to what others have explained, local imports are necessary
for template mixins:
http://ddili.org/ders/d.en/mixin.html#ix_mixin.import,%20local
Quoting:
module a;
import std.string; // ← wrong place
mixin template A(T) {
string a() {
T[] array;
// ...
return format("%(%s, %)", array);
}
}
"if std.string is not imported at the actual mixin site, then the
compiler would not be able to find the definition of format() at that point"
module a;
mixin template A(T) {
string a() {
import std.string; // ← right place
T[] array;
// ...
return format("%(%s, %)", array);
}
}
Ali
More information about the Digitalmars-d-learn
mailing list