www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Use of "T"

reply solidstate1991 <laszloszeremi outlook.com> writes:
Some utilities of my game engine needs a two-way "dictionary", 
mainly for increasing the readability of configuration files, but 
I was thinking on letting the end-user to use it for certain 
things and I don't want to recreate the encode/decode/load from 
SDLang file functions every time I have to use a similar thing. 
Currently I need to use it for int<->string conversion only (key 
names, button names, axis names, etc.), in the future I might use 
it for even more purpose (language files are planned to use XML 
due to the possibility of using UTF16, as the engine's native 
character handling is using it, not to mention the easier 
formatting via markup).

How can I make use of T? I've seen it being used many times for 
this application.
Apr 12 2017
parent reply qznc <qznc web.de> writes:
On Wednesday, 12 April 2017 at 13:17:42 UTC, solidstate1991 wrote:
 How can I make use of T? I've seen it being used many times for 
 this application.
What "T"? This letter is often used as a generic template parameter. Are you talking about templates? Maybe you can give some examples of the "many times" you have seen it used?
Apr 12 2017
parent reply solidstate1991 <laszloszeremi outlook.com> writes:
On Wednesday, 12 April 2017 at 13:54:11 UTC, qznc wrote:
 On Wednesday, 12 April 2017 at 13:17:42 UTC, solidstate1991 
 wrote:
 How can I make use of T? I've seen it being used many times 
 for this application.
What "T"? This letter is often used as a generic template parameter. Are you talking about templates? Maybe you can give some examples of the "many times" you have seen it used?
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. 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.
Apr 12 2017
parent reply XavierAP <n3minis-git yahoo.es> writes:
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;
Apr 12 2017
parent reply solidstate1991 <laszloszeremi outlook.com> writes:
On Wednesday, 12 April 2017 at 16:05:23 UTC, XavierAP wrote:
 On Wednesday, 12 April 2017 at 14:46:20 UTC, solidstate1991 
 wrote:
 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
 So according to the spec linked above, those examples would be 
 declared:

 string[int] dict1;
 string[string] dict2;
 int[string] dict3;
I know the existence of those and I'm frequently using them, however I need a two-way one. (Might be using two hash-tables instead if I can't find a better solution)
Apr 12 2017
parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
On Wednesday, 12 April 2017 at 22:56:25 UTC, solidstate1991 wrote:

 I know the existence of those and I'm frequently using them, 
 however I need a two-way one. (Might be using two hash-tables 
 instead if I can't find a better solution)
So, you're looking for a generic way to store objects of arbitrary types in a file, and later retrieve those objects from that file? If that's the case, try looking at some existing serialization solutions (i.e. https://wiki.dlang.org/Serialization_Libraries).
Apr 12 2017