C++ overloading operators difference between == and <

前端 未结 6 1306
花落未央
花落未央 2021-01-21 17:01

Could anybody explain me what is the difference between overload == and <?

For example, if I use a map:

map         


        
6条回答
  •  迷失自我
    2021-01-21 17:29

    The operator < is needed, because the find operation bases on the inner implementation of map (on the tree). To be able to find in complexity better than linear, it can't have to compare with every element.

    A good example of the similar algorithm is Binary Search. As you can see in sample pseudocode, it doesn't use the identity operator at all.

提交回复
热议问题