A simple question

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Thu Nov 15 19:24:25 PST 2012


On Fri, 16 Nov 2012 03:55:53 +0100
"Stugol" <stugol at gmx.com> wrote:

> On Friday, 16 November 2012 at 02:22:32 UTC, Adam D. Ruppe wrote:
> > On Friday, 16 November 2012 at 02:00:05 UTC, Stugol wrote:
> >> Hmm, that makes a bit more sense now I guess. Funny, I don't 
> >> remember seeing that rule when I read the documentation.
> >
> > It might not be clear, but it is there:
> >
> > http://dlang.org/module.html
> > "The ModuleDeclaration sets the name of the module and what 
> > package it belongs to. If absent, the module name is taken to 
> > be the same name (stripped of path and extension) of the source 
> > file name."
> >
> > The parenthesis is important in this case - once the name is 
> > stripped of path, it only leaves a simple name, no more package 
> > info.
> 
> I'm not quite sure what purpose the MODULE keyword serves in any 
> case. I have a file "Include.D\Infinity\Standard\Mixins\Event.d", 
> but if I give it a module name of "infinity.standard.event" it 
> doesn't work. I have to include the ".mixins" part. So what's the 
> point?
> 

It sounds like you're using something that does automatic dependency
tracking, like RDMD (maybe VisualD uses RDMD behind the scenes?) The
only way those *can* work is of the filename/path matches (othewrwise,
if it needs to find a module named "foo.bar.bat", it has no way to know
where to find it if it's not in something named "foo/bar/bat.d").

In order to have module/package names that differ from the file/path
names, the only way for that to work is if you pass those files in
explicitly. Otherwise the compiler or build system would have to read
every file on your computer hoping to find one that included the text
"module foo.bar.bat;". Naturally, that wouldn't be a good idea ;)

Since it can be a pain to track all of your files manually, most people
just follow the "module/package name == file/path name" convention so
they can use an auto-dependency tool like RDMD.


> Also, I'm having difficulty specifying a default specialisation 
> for a template class:
> 
>     class Event(TEventArgs : EventArgs = EventArgs) {
>     }

That would probably normally be:

    class Event(TEventArgs = EventArgs) {
    }

Unless you really are requiring that TEventArgs must be either
EventArgs or something derived from EventArgs. (Maybe you are?)

> 
> Usage:
> 
>     Event!() e1;     // Works
>     Event e2;        // Won't compile
> 
> How can I have "Event" be an alias for "Event!EventArgs"?

I think function templates are the only kind that can be instantiated
without the "!()" part. So "Event" just refers to the template itself,
not the class inside it.

You may be able to do this:

    alias Event!() Event;

But I don't know if that would result in a naming conflict.



More information about the Digitalmars-d mailing list