Thread overview |
---|
October 07, 2013 Get unique id of a class type. | ||||
---|---|---|---|---|
| ||||
I'm looking a way to get the unique id of a class. I'm able to do this in C++ using type_info::hash_code(). void function(T) { auto id = typeid(T).getHash(); // Something like this? // I know i could write this but seems ugly to me :/ auto id = typeid(string).getHash(typeid(T).name); // Or maybe even better. auto id = typeid(T).id; // ID is not a number but a class for storing } |
October 07, 2013 Re: Get unique id of a class type. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Agustin | On Monday, 7 October 2013 at 18:55:58 UTC, Agustin wrote: > I'm looking a way to get the unique id of a class. I'm able to do > this in C++ using type_info::hash_code(). > > void function(T) { > auto id = typeid(T).getHash(); // Something like this? > > // I know i could write this but seems ugly to me :/ > auto id = typeid(string).getHash(typeid(T).name); > > // Or maybe even better. > auto id = typeid(T).id; // ID is not a number but a class for > storing > } Have you tried toHash()? https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L211 |
October 07, 2013 Re: Get unique id of a class type. | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | On Monday, 7 October 2013 at 19:07:19 UTC, simendsjo wrote:
> On Monday, 7 October 2013 at 18:55:58 UTC, Agustin wrote:
>> I'm looking a way to get the unique id of a class. I'm able to do
>> this in C++ using type_info::hash_code().
>>
>> void function(T) {
>> auto id = typeid(T).getHash(); // Something like this?
>>
>> // I know i could write this but seems ugly to me :/
>> auto id = typeid(string).getHash(typeid(T).name);
>>
>> // Or maybe even better.
>> auto id = typeid(T).id; // ID is not a number but a class for
>> storing
>> }
>
> Have you tried toHash()?
> https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L211
I Think that would return the hash of every member of a class, rather than just the hash of the class name
|
October 07, 2013 Re: Get unique id of a class type. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Agustin | On Monday, 7 October 2013 at 19:24:32 UTC, Agustin wrote:
> On Monday, 7 October 2013 at 19:07:19 UTC, simendsjo wrote:
>> On Monday, 7 October 2013 at 18:55:58 UTC, Agustin wrote:
>>> I'm looking a way to get the unique id of a class. I'm able to do
>>> this in C++ using type_info::hash_code().
>>>
>>> void function(T) {
>>> auto id = typeid(T).getHash(); // Something like this?
>>>
>>> // I know i could write this but seems ugly to me :/
>>> auto id = typeid(string).getHash(typeid(T).name);
>>>
>>> // Or maybe even better.
>>> auto id = typeid(T).id; // ID is not a number but a class for
>>> storing
>>> }
>>
>> Have you tried toHash()?
>> https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L211
>
> I Think that would return the hash of every member of a class, rather than just the hash of the class name
Nevermind, i just saw the link you gave me, thanks a lot!.
|
Copyright © 1999-2021 by the D Language Foundation