In my post "Template alias parameter mixin import inference" ( http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=68798 ), and in bug 2125 ( http://d.puremagic.com/issues/show_bug.cgi?id=2125, "Moving a template to a separate module breaks compilation" ), it is demonstrated that giving a template access to both its declaration scope and its instantiation scope might give more logical and desireable behavior.
Example code:
//////////////////////
module a;
import std.stdio;
template bar()
{
int i;
void func()
{
writefln(i);
}
}
void main()
{
foo!(bar) a;
a.func();
}
//////////////////////
module b;
struct foo(alias T)
{
mixin T!();
}
//////////////////////
Gives error message "b.d(5): Error: undefined identifier writefln".
Currently, this can be fixed by placing import statements within the template declaration, but allowing access to more scopes would make it easier for the programmer.
Comment #1 by razvan.nitu1305 — 2019-09-09T13:43:02Z
Templates are evaluated in the context where they are instantiated. If a template needs a specific symbol it is cleaner to declare in the templates' scope rather than creating symbol resolution rules for templates.
Closing on the same grounds as issue 2125.