HashCodeBuilder in C ++

If I want to generate a hash for a given object in Java, the easiest way I know is to use 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 something similar in C ++?

+3
source share
2 answers

By the way, the hashCode method does not return the identifier of the object. This is a common misconception. There is nothing that would prevent two objects of the same class from returning the same value. The hash code is for hash table data structures, not for identifying objects. These are two separate concepts.

0
source

Source: https://habr.com/ru/post/1715698/


All Articles