It returns the index of the bucket to which the key belongs, regardless of whether the key is inserted or not.
From the Standard (C ++ 11, ยง23.2.5, Table 103, p. 752):
b.bucket(k)
Returns the bucket index in which elements with keys equivalent to k will be found if such an element existed.
The only precondition is b.bucket_count > 0 (which is almost always the case). Theoretically, the default constructor unordered_multimap allowed to generate an initial hash with zero buckets, but I doubt that any implementation actually does this).
To check if a key exists (i.e. inserted), use
b.count(key) > 0
as you said or
b.find(key) != b.end()
(I would suggest that the latter tends to be more efficient, because checking for existence is, generally speaking, less effort than counting. This would be especially true in unordered_multimap .)
source share