D import idiom compilation time

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Jan 5 04:13:05 UTC 2019


On Fri, Jan 04, 2019 at 08:54:44PM -0500, Andrei Alexandrescu via Digitalmars-d wrote:
> On 1/4/19 8:11 AM, bauss wrote:
> > On Thursday, 3 January 2019 at 23:54:42 UTC, SrMordred wrote:
> > > struct _std
> > > {
> > >   template opDispatch(string moduleName)
> > >   {
> > >     mixin("import opDispatch = std." ~ moduleName ~ ";");
> > >   }
> > > }
> > 
> > 
> > There is nothing that's actually stopping you from just calling it
> > std.
> > 
> > It will work just as fine.
> > 
> > That way you can end up with
> > 
> > std.stdio.writeln("...");
> > 
> > Instead of:
> > _std.stdio.writeln("...");
> 
> This is quite amazing.

It doesn't have to be tied to a specific root package. Just call it
"autoimport", or something short like "from":

	struct from
	{
	  template opDispatch(string moduleName)
	  {
	    mixin("import opDispatch = " ~ moduleName ~ ";");
	  }
	}

Then just write:

	from.std.stdio.writeln("...");
	from.some.other.package.func(1, 2, 3);

and so on.


T

-- 
Doubtless it is a good thing to have an open mind, but a truly open mind should be open at both ends, like the food-pipe, with the capacity for excretion as well as absorption. -- Northrop Frye


More information about the Digitalmars-d mailing list