www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Get the default hash function.

reply "francesco cattoglio" <francesco.cattoglio gmail.com> writes:
Really simple question:
how do I get the compiler-generated hash function for a given 
type?

For example:
Struct S
{
     int i;
}

can be used in an associative array. That means the compiler 
generates a "toHash" function. Is there any simple way to call it 
directly?
Jul 31 2014
next sibling parent "FreeSlave" <freeslave93 gmail.com> writes:
On Thursday, 31 July 2014 at 12:05:53 UTC, francesco cattoglio 
wrote:
 Really simple question:
 how do I get the compiler-generated hash function for a given 
 type?

 For example:
 Struct S
 {
     int i;
 }

 can be used in an associative array. That means the compiler 
 generates a "toHash" function. Is there any simple way to call 
 it directly?
I believe you may use typeid to get TypeInfo instance. It has
Jul 31 2014
prev sibling parent "H. S. Teoh via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com> writes:
On Thu, Jul 31, 2014 at 12:05:52PM +0000, francesco cattoglio via
Digitalmars-d-learn wrote:
 Really simple question:
 how do I get the compiler-generated hash function for a given type?
 
 For example:
 Struct S
 {
     int i;
 }
 
 can be used in an associative array. That means the compiler generates
 a "toHash" function. Is there any simple way to call it directly?
struct S { int i; } void main() { auto s = S(123); import std.stdio; writeln(typeid(s).getHash(&s)); } T -- "Maybe" is a strange word. When mom or dad says it it means "yes", but when my big brothers say it it means "no"! -- PJ jr.
Jul 31 2014