开发者

Why does STL set have count() when all elements are supposed to be unique?

开发者 https://www.devze.com 2023-01-28 08:10 出处:网络
I can understand that multiset has count(), for counting the number of 开发者_JAVA百科occurrences of a value, because elements can be repeated in multiset.

I can understand that multiset has count(), for counting the number of 开发者_JAVA百科occurrences of a value, because elements can be repeated in multiset. But what's the point of having count() in set, when all the values are already unique?


count is part of the associative container requirements(1).

Every associative container is required to provide it as part of its interface, even if the result is always zero or one as is the case with std::set.


(1) This is a link to the SGI STL documentation describing the Associative Container concept; the concept as defined in the C++ standard may differ slightly, but not substantially.

0

精彩评论

暂无评论...
验证码 换一张
取 消