Lazy private selective imports
monarch_dodra
monarchdodra at gmail.com
Mon Mar 24 14:43:35 PDT 2014
On Monday, 24 March 2014 at 21:21:30 UTC, Andrej Mitrovic wrote:
> On Monday, 24 March 2014 at 21:18:49 UTC, Peter Alexander wrote:
>> Would it be possible to perform private selective imports
>> lazily?
>
> This was discussed fairly recently:
> http://forum.dlang.org/thread/l8t2o1$kq0$1@digitalmars.com?page=9
> (and previous or next pages)
This is a very recent issue, as a matter of fact, I ran into it
*TODAY*:
https://github.com/D-Programming-Language/phobos/pull/2047
By combining templates and aliases, you can have a library
solution:
//----
template lazyWriteln()
{
import std.stdio : writeln;
alias lazyWriteln = std.stdio.writeln;
}
void main()
{
lazyWriteln(5);
}
//----
Heck, with proper renamed imports, you can even re-use the
initial name:
//----
template writeln()
{
import std.stdio : stdwriteln = writeln;
alias writeln = stdwriteln;
}
void main()
{
writeln(5);
}
//----
HOWEVER (word of warning), for the second solutions, I've run
into conflicting alias issues:
std/conv.d(4864): Error:
std.string.format!(char, uint, string, uint).format at
std/string.d(2401)
conflicts with
std.string.format!(char, uint, string, uint).format at
std/string.d(2401)
I didn't dig very far to know if this is 313/314 related, or a
new issue though.
In any case, while not as convenient as a built-in "lazy import",
it could be a solution worth digging into.
More information about the Digitalmars-d
mailing list