D import idiom compilation time

Daniel N no at public.email
Sun Jan 6 12:11:41 UTC 2019


On Saturday, 5 January 2019 at 23:44:31 UTC, H. S. Teoh wrote:
> On Sat, Jan 05, 2019 at 10:48:30PM +0000, Dgame via 
> Digitalmars-d wrote: [...]
>> Output:
>> 
>> ----
>> Hallo
>> core.exception.AssertError at onlineapp.d(20): Symbol
>> "thisFunctionDoesNotExist" not found in std.stdio
>> ----------------
>> ??:? _d_assert_msg [0x3c00dc54]
>> onlineapp.d:20 pure nothrow @nogc @safe void
>> onlineapp.FailedSymbol!("thisFunctionDoesNotExist",
>> "std.stdio").FailedSymbol!(immutable(char)[]).FailedSymbol(immutable(char)[])
>> [0x3c00ceac]
>> onlineapp.d:52 _Dmain [0x3c00c8c3]
>> ----
>
> Impressive!  Though we pretty much had to bring out the nuclear 
> warhead to get here. :-D  By this point I wonder if it has 
> already made the original reason for doing this moot compared 
> to just directly importing the symbol! :-P
>
>
> T

Nice, just surprised it took this long, I made the opDispatch 
snippet challenge in the blog nearly 2 years ago. I had assumed 
people would jump all over it. (like you now did in this thread).

https://dlang.org/blog/2017/02/13/a-new-import-idiom/
> Now then, is this the only solution? No. As a challenge to the 
> reader, try to figure out what this does and, more importantly, 
> its flaw. Can you fix it?
>
> static struct STD
> {
>   template opDispatch(string moduleName)
>   {
>     mixin("import opDispatch = std." ~ moduleName ~ ";");
>   }
> }



More information about the Digitalmars-d mailing list