Use of "T"

XavierAP via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 12 09:05:23 PDT 2017


On Wednesday, 12 April 2017 at 14:46:20 UTC, solidstate1991 wrote:
>
> Yes, templates. I've looked this up a bit, and I found it. I 
> want to use it to use the dictionaries for different things 
> than string<->int conversion.

T is just the common name of a (type) parameter, mostly whenever 
the template is more generic that you can't think of a more 
informative (template) parameter name. Just like you could use 
"str" for a string or "i" for an int name. But in you case you 
could use a more informative name such as "keyType" since you are 
describing keyType -> valueType dictionaries, also called 
associative arrays.

Moreover these dictionaries are built-in basic types in D:
https://dlang.org/spec/hash-map.html

> This should be the Dictionary(int), string<->string conversion 
> should be done with Dictionary(string). Int<->string should be 
> done as Dictionary(string,int) if possible.

So according to the spec linked above, those examples would be 
declared:

string[int] dict1;
string[string] dict2;
int[string] dict3;


More information about the Digitalmars-d-learn mailing list