import all except specified symbols: eg import std.stdio:!writeln,write;

Jacob Carlborg doob at me.com
Sun Sep 9 23:36:30 PDT 2012


On 2012-09-10 02:07, Jonathan M Davis wrote:

> You could create a new module that publicly imports all of the symbols that
> you want and not the ones that you don't. Then have your existing module
> import that one. But that just moves the verboseness to another module, which
> _could_ save you some typing if you're doing the same thing in multiple
> modules, or it could be juts moving the problem to another module, making
> things even _more_ verbose.
>
> The normal thing to do is to simply use the whole import path when there's a
> conflict. e.g.
>
> std.ascii.isAlpha(var1);
> std.uni.isAlpha(var2);
>
> If you want to make it less verbose, you can rename the import
>
> import stuff = my.really.long.import.path
>
> stuff.func(5);
>
> And there's always alias,
>
> alias std.ascii.isAlpha isAlpha;
>
> but be aware that that will affect every module which imports yours (even if
> you make the alias private - since private effects access, not overload
> resolution), so it's generally a bad idea to use an alias like that unless you
> name it something completely different. e.g.
>
> private alias std.ascii.isAlpha isOmega;

If we're just thinking from a technical view it might be possible. 
Something like:

mixin(importExcept!(std.stdio, "write", "writeln"));

If it's possible to get all symbols from another module then it's easy 
to just exclude a few symbols and create imports for the rest.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list