Talk:cpp/container/set/count

They keys of std::set are supposed to be unique. For instance, GCC STL returns 0/1:

/**      *  @brief  Finds the number of elements. * @param  x  Element to located. * @return  Number of elements with specified key. *      *  This function only makes sense for multisets; for set the result will * either be 0 (not present) or 1 (present). */     size_type count(const key_type& __x) const { return _M_t.find(__x) == _M_t.end ? 0 : 1; }


 * Yes, the number of elements with the key equivalent to Key can only be zero or one for set and map. I agree that it is worth mentioning explicitly (at least we could simplify the 'Complexity' clause). --Cubbi (talk) 06:58, 24 January 2014 (PST)

Note that this is not necessarily the case for the heterogeneous search, as multiple keys can compare equivalent to the argument of type K. See also https://stackoverflow.com/questions/46632871/can-we-use-heterogeneous-lookup-comparator-to-perform-a-partial-match-search-o and a related bug in libc++: http://lists.llvm.org/pipermail/llvm-bugs/2016-November/051888.html