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?
Sets are a type of associative container in which each element has to be unique because the value of the element identifies it. The values are stored in a specific sorted order i.e. either ascending or descending.
The COUNT function counts the number of cells that contain numbers, and counts numbers within the list of arguments. Use the COUNT function to get the number of entries in a number field that is in a range or array of numbers.
The set::count() is a built-in function in C++ STL which returns the number of times an element occurs in the set. It can only return 1 or 0 as the set container contains unique elements only. Parameters: The function accepts one mandatory parameter element which specifies the element whose count is to be returned.
Properties of set in C++ The property of Uniqueness: Every element of a set in C++ must be unique, i.e., no duplicate values are allowed.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With