QMap -> what does .contains() compare?
-
Hello there,
running Qt 6.6 am wondering, what the .contains() method of QMap uses to compare.
The documentation says
"Returns true if the map contains an item with key key; otherwise returns false."
For me that sounds too generic to be sure - I mean, it could be a hash-value get´s created behind the scenes, or the memory address ocupied is sompared.ChatGPT said it uses the default comparsion operator defined of the class type used as KEY.
-> Is that correct? And if so, where do I find that information?Given it is, how do I know which of let´s say QTime overloaded operators is the default comparsion one?
-
@Flaming-Moe said in QMap -> what does .contains() compare?:
Hello there,
running Qt 6.6 am wondering, what the .contains() method of QMap uses to compare.
The documentation says
"Returns true if the map contains an item with key key; otherwise returns false."
For me that sounds too generic to be sure - I mean, it could be a hash-value get´s created behind the scenes, or the memory address ocupied is sompared.Hash is generated in
QHash
, not inQMap
.ChatGPT said it uses the default comparsion operator defined of the class type used as KEY.
-> Is that correct? And if so, where do I find that information?Yes.
Given it is, how do I know which of let´s say QTime overloaded operators is the default comparsion one?
The one which overloads the comparison:
bool opearator==(const QTime &other) const
. -
@Flaming-Moe said in QMap -> what does .contains() compare?:
"Returns true if the map contains an item with key key; otherwise returns false."
For me that sounds too generic to be sure - I mean, it could be a hash-value get´s created behind the scenes, or the memory address ocupied is sompared.Comparing means operator==(), or do you compare your stuff with something else?
-
Okay I was not aware, that == is the compare operator
since others are also overloaded
bool operator<=(QTime lhs, QTime rhs) bool operator==(QTime lhs, QTime rhs) bool operator>(QTime lhs, QTime rhs) bool operator>=(QTime lhs, QTime rhs)