Workaround for DIP 1005

Jack Stouffer via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 7 07:11:53 PST 2017


On Tuesday, 7 February 2017 at 15:00:17 UTC, Andrea Fontana wrote:
> 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.

Because Systime's are used in the signiture, a local import 
cannot be used. Local imports are only evaluated if the function 
is used in the program and are local to that scope. Therefore, 
when the signitures are being evaluated, the compiler has no 
information about std.datetime, and therefore fails with a symbol 
not found error.


More information about the Digitalmars-d mailing list