2 problems I can't get my head around

Dan dbdavidson at yahoo.com
Mon Nov 26 05:45:31 PST 2012


On Monday, 26 November 2012 at 12:32:08 UTC, Manu wrote:
> 2.
>
> import std.stdio;
> pragma(msg, !is(std) && is(typeof(std))); // <- true?!
>
> std.stdio is a module, it looks like a variable. typeof(std) == 
> void...
> What the? Why does it even have a type?
> I can't find a sensible way to distinguish std from any other 
> regular
> variable.

traits uses something like this (see fullyQualifiedName)

Thanks
Dan

import std.stdio;

template isPackage(alias name) {
   static if(name.stringof.length >= 9 && name.stringof[0..8] == 
"package ") {
     enum isPackage = true;
   } else {
     enum isPackage = false;
   }
}

void main() {
   pragma(msg, "Is std a package:", isPackage!std);
   pragma(msg, "Is std.stdio a package:", isPackage!(std.stdio));
}




More information about the Digitalmars-d mailing list