imports in functions
Andrej Mitrovic
andrej.mitrovich at gmail.com
Mon Jun 13 12:52:51 PDT 2011
I'm having some fun with this.
import std.array;
void main()
{
with (namespace!("std.stdio std.algorithm std.range"))
{
auto squares = map!("a * a")([2, 4, 6]);
writeln(squares);
}
}
template namespace(string x)
{
mixin(namespaceImpl(x));
}
string namespaceImpl(string x)
{
string result;
auto mods = split(x);
foreach (val; mods)
{
result ~= "import " ~ val ~ ";";
}
return result;
}
More information about the Digitalmars-d
mailing list