当所有元素都应该是唯一的时,为什么 STL 集合有 count() ?

发布于 2024-10-05 23:43:24 字数 104 浏览 0 评论 0原文

我可以理解multiset有count(),用于计算一个值出现的次数,因为元素可以在multiset中重复。 但是,当所有值都已经是唯一的时,将 count() 放入 set 中还有什么意义呢?

I can understand that multiset has count(), for counting the number of 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后eg是否自 2024-10-12 23:43:24

count关联容器要求的一部分(1)

每个关联容器都需要将其作为其接口的一部分提供,即使结果始终为零或一(如 std::set 的情况)。


(1) 这是描述关联容器概念的 SGI STL 文档的链接; C++ 标准中定义的概念可能略有不同,但差别不大。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文