Workaround for DIP 1005
Andrea Fontana via Digitalmars-d
digitalmars-d at puremagic.com
Tue Feb 7 07:00:17 PST 2017
On Friday, 3 February 2017 at 15:41:56 UTC, Daniel N wrote:
> On Friday, 3 February 2017 at 14:43:01 UTC, Dominikus Dittes
> Scherkl wrote:
>> DIP 1005 provides new syntax to make it possible to avoid
>> global imports.
>> Any thoughts?
>
> I like it!
>
> template imp(string mod)
> {
> mixin("import imp = " ~ mod ~ ";");
> }
>
> auto fun_time(imp!"std.datetime".SysTime tm)
> {
> return tm;
> }
>
> void main()
> {
> import std.stdio;
> import std.datetime;
>
> fun_time(Clock.currTime()).writeln;
> }
I don't understand why we can't use a template like:
auto fun_time(SysTime)(SysTime tm)
{
import std.datetime;
static assert (is(SysTime == std.datetime.SysTime));
return tm;
}
void main()
{
import std.stdio;
import std.datetime;
fun_time(Clock.currTime()).writeln;
}
I think I missed something.
More information about the Digitalmars-d
mailing list