当所有元素都应该唯一时,为什么STL set具有count()? [英] Why does STL set have count() when all elements are supposed to be unique?

查看:47
本文介绍了当所有元素都应该唯一时,为什么STL set具有count()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

count 每个结果容器都需要提供它作为其接口的一部分,即使结果始终为零或一,如 std :: set 一样.

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)这是指向描述关联容器概念的SGI STL文档的链接;C ++标准中定义的概念可能略有不同,但没有实质性差异.

(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.

这篇关于当所有元素都应该唯一时,为什么STL set具有count()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆