How to avoid multiple spelling `import`

tired_eyes via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 16 09:40:36 PDT 2015


On Tuesday, 16 June 2015 at 15:42:02 UTC, Dennis Ritchie wrote:
> On Tuesday, 16 June 2015 at 12:41:14 UTC, Daniel Kozák wrote:
>>
>> On Tue, 16 Jun 2015 11:45:22 +0000
>> Dennis Ritchie via Digitalmars-d-learn
>> <digitalmars-d-learn at puremagic.com> wrote:
>>> I just want to import individual features of these modules.
>>
>> mixin template include(w...)
>> {
>>     mixin _include!(w.length - 1, w);
>> }
>>
>> mixin template _include(long N, i...)
>> {
>>
>>     mixin("import " ~ i[N] ~ ";");
>>     mixin _include!(N - 1, i);
>> }
>>
>> mixin template _include(long N : 0, i...)
>> {
>>
>>     mixin("import " ~ i[N] ~ ";");
>> }
>>
>> mixin include!(
>>     "std.stdio : writeln, write",
>>     "std.conv : to"
>> );
>>
>> void main() {
>>     writeln(to!string(7));
>> }
>
> Thanks. Maybe I'll use this code in your own programs.
>
> I still believe that this design deserves existence in D:
> https://issues.dlang.org/show_bug.cgi?id=14704

I also think this might be useful, and, more important, 
consistent. If we have shorthand syntax for full imports, why 
there is no option for shorthand partial imports? This is 
expected behavior.


More information about the Digitalmars-d-learn mailing list