A simple question

Adam D. Ruppe destructionator at gmail.com
Thu Nov 15 19:26:16 PST 2012


On Friday, 16 November 2012 at 02:55:54 UTC, Stugol wrote:
> 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?

I haven't used VisualD but I suspect it is assuming filenames 
based on import declarations.

You don't have to do it this way though. If all the modules are 
passed on the one command, with a manual listing, the filename 
doesn't matter. It only uses the module line then. That's useful 
for times when your folder structure doesn't exactly match.


Let me give you an example. For one of my work projects, we 
compile it differently for different clients. What I do is have a 
bunch of different configuration/customization files:

custom_acme.d
custom_bugs.d
custom_daffy.d

Each of these has the same module line:

module myproduct.configuration;
/* then various config variables and little customizations are 
next */


Then the main app never knows about the different clients. It 
just does

import myproduct.configuration;

and it all just works. Now, if I want to build the one for Acme, 
I do: dmd myapp.d custom_acme.d, and it is good.

If I want to make the one for Bugs, I just do: dmd myapp.d 
custom_bugs.d and have their version.

If they buy a source license, I can send just their file without 
changing anything else and without exposing any of the other 
client's custom code.



It's something you might never need, but is really nice to have 
when it does come up.

> Also, I'm having difficulty specifying a default specialisation 
> for a template class:

Yea... even with default args, you still have to use the !() to 
tell it that you actually want the template instantiated.

One option would be to do something like this:

class EventBase(int a = 0) {
}

alias EventBase!(0) Event;

void main() {
         EventBase!() e1;
         Event e2;
}


The alias line can include template arguments and then will work. 
But it needs to have a different name than the class itself so 
the names don't conflict.


I don't think there's any other way... either has to be Event!() 
like you had, or use the alias like I did here.


More information about the Digitalmars-d mailing list