scoped imports

bearophile bearophileHUGS at lycos.com
Sat Aug 17 16:23:03 PDT 2013


Timothee Cour:

> Is there a way to achieve this:
>
> ----
> module foo;
>
> {
> import bar;
> void fun1(){bar.barfun();}
> void fun2(bar.BarType a){}
> }
>
> // now bar is not in scope anymore.

Using a struct as namespace:


struct Foo {
     import std.stdio;
     static void bar(int x) { x.writeln; }
}
alias bar = Foo.bar;

void main() {
     bar(10);
     // writeln(20); // std.stdio out of scope
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list