[Issue 2770] New: Example code would help in Modules documentation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 29 12:20:39 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2770

           Summary: Example code would help in Modules documentation
           Product: D
           Version: 2.026
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: steve.teale at britseyeview.com


For instance:

module example;

import std.stdio;

template factorial(int n)
{
   static if (n == 1)
      enum { factorial = 1 }
   else
      enum { factorial = n* factorial!(n-1) }
}

int _mmm;

static this()
{
   writefln("module initializing");
   _mmm = factorial!(4);

   // If you uncomment the throw, then the static destructor will not get   
   // called.
   // throw new Exception("What happened");
}

static ~this()
{
   writefln("Gone now");
}

void main()
{
   writefln(_mmm);
}


-- 



More information about the Digitalmars-d-bugs mailing list