Why is the C++ STL set container's count() method thus named?

前端 未结 3 1658
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 03:13

What it really checks for is contains() and not the count of the number of occurrences, right? Duplicates are not permitted either so wouldn\'t contains() be a better name t

3条回答
  •  鱼传尺愫
    2020-12-11 03:48

    It's a standard operation on containers that returns the number of matching elements. In things like lists, this makes perfect sense. It just so happens that on a set, there can only be one occurrence of an element and therefore count can never return a value greater than 1.

提交回复
热议问题