hasmap with tuple as key

2015-02-09 Thread Ondra via Digitalmars-d-learn

Is there any drawback of doing this: string[Tuple!(int, int)] a;

Especially performance one.

Thanks.


Re: getting all children classes in program

2015-01-03 Thread Ondra via Digitalmars-d-learn

Hi Baz  jklp,

thank you for ideas I will use your approach for this problem.


Re: getting all children classes in program

2015-01-03 Thread Ondra via Digitalmars-d-learn




I'm not sure if there's a way around that other than to add 
some code in the class to register itself. You could use a 
static constructor that adds itself to a list.


Or, to give each class a shared ID, you could add a static 
member which returns some variation of its typeinfo. In fact, 
typeid(any_class) returns a unique identifier for each class 
(an instance of TypeInfo), maybe you can use it directly.


Hi Adam,

static this is probably way to go, I wanted to avoid this 
solution because if it leads to copy-pasting code to every child.


I need to have IDs small like 8bits, co I probably can't use 
typeid...


Thank you for answer. Knowing that someting cannot be done is 
better than spend on this another few hour.


Great book btw.

Ondra


getting all children classes in program

2015-01-03 Thread Ondra via Digitalmars-d-learn

Hi,

how can I get list of all children classes of class in program? I 
was trying to use ModuleInfo from D Coockbook but this does not 
work for template classes?


ex.:
class A{}
class B:A{} // ok in ModuleInfo
class C(T): B {} // missing in ModuleInfo

I am trying to assign every class its unique ID that is same for 
all instances.


Code:
int result[string];

int counter = 0;
foreach(mod; ModuleInfo)
{
foreach(cla; mod.localClasses)
{
auto base = cla.base;
while (base)
{
if (base is T.classinfo)
{
result[cla.name] = counter;

counter++;
}

base = base.base;
}
}
}