I have a multimap with some keys being duplicates. When I search for a key using equal_range(), I get a pair of iterators back. When the key is duplicate, the iterators are pointing to the first and the last values in the multimap.
the iterators are pointing to the first and the last values in the multimap
Wrong.
Second iterator is past-the end iterator for returned range. So first and second iterators will be same only if key is not found at all (empty range). To get number of elements found use std::distance(ret.first, ret.second)