Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HashCodeBuilder in C++

Tags:

java

c++

hashcode

If I want generate a hash for a given object in Java, the easiest way I know is to use the Apache Commons HashCodeBuilder:

public class Person {
   String name;
   int age;
   boolean smoker;
   ...

   public int hashCode() {
     // you pick a hard-coded, randomly chosen, non-zero, odd number
     // ideally different for each class
     return new HashCodeBuilder(17, 37).
       append(name).
       append(age).
       append(smoker).
       toHashCode();
   }
 }

Is there anything similar in C++?

like image 886
wupher Avatar asked May 18 '26 11:05

wupher


1 Answers

Use boost::hash_combine.

like image 159
Martin v. Löwis Avatar answered May 19 '26 23:05

Martin v. Löwis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!