454,605 Members | 1,370 Online Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

# how to customize compare function of std map class?

 P: n/a key_compare can only return true, false , but how about equal happens? Nov 15 '06 #1
5 Replies

 P: n/a "thinktwice"

 P: n/a * thinktwice: key_compare can only return true, false , but how about equal happens? key_compare compares two keys a and b as if via "a < b" with an operator< defined for the key type, so equal keys will/should yield false. a < b <= b a !(a < b) <= a >= b b < a <= a b !(b < a) <= b >= a a == b <= (a >= b) && (b >= a) <= !(a < b) && !(b < a) And applying De Morgan's theorem, a == b <= !(a < b) && !(b < a) <= !((a < b) || (b < a)) -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? Nov 15 '06 #3

 P: n/a thanks, i have customize the compare function, but seems it doesn't work. is there anything wrong? struct myVariantCompare{ bool operator()(VARIANT v1, VARIANT v2) { if (v1.vt == v2.vt) { if (v1.vt == VT_UNKNOWN) { CComPtr

 P: n/a thanks, i have customize the compare function, but seems it doesn't work. is there anything wrong? struct myVariantCompare{ bool operator()(VARIANT v1, VARIANT v2) { if (v1.vt == v2.vt) { if (v1.vt == VT_UNKNOWN) { CComPtr

 P: n/a thinktwice wrote: thanks, i have customize the compare function, but seems it doesn't work. is there anything wrong? struct myVariantCompare{ inherit from binary_function bool operator()(VARIANT v1, VARIANT v2) this should be const { if (v1.vt == v2.vt) { if (v1.vt == VT_UNKNOWN) { why not assert here instead and loose the branch? CComPtr

### This discussion thread is closed

Replies have been disabled for this discussion. 