#include template< class Key, class Compare = std::less, class Allocator = std::allocator > class multiset : public std::multiset { typedef multiset self; typedef std::multiset parent; public: typedef typename parent::iterator iterator; typedef typename parent::const_iterator const_iterator; // returns iterator poiting to first element equal to key. const_iterator equal( const Key& key ) const { const_iterator eq = self::lower_bound(key); if(eq == self::end() || *eq != key) { return self::end(); } else { return eq; } } // returns iterator poiting to first element equal to key. // if no such element exists, return iterator pointing to last element less than key. const_iterator equal_or_less( const Key& key ) const { if(self::size() == 0) { return self::end(); } else { const_iterator equal_or_greater = self::lower_bound(key); if(equal_or_greater == self::end()) { // no element is equal or greater, so take the last return --self::end(); } else if(*equal_or_greater == key) { return equal_or_greater; } else if(equal_or_greater == self::begin()) { return self::end(); } else { return --equal_or_greater; } } } const_iterator equal_or_less_or_max( const Key& key ) const { const_iterator eq_or_less = self::equal_or_less(key); if(eq_or_less == self::end()) { return self::max(); } else { return eq_or_less; } } const_iterator greater_or_min( const Key& key ) const { const_iterator greater = self::upper_bound(key); if(greater == self::end()) { return min(); } else { return greater; } } // returns an iterator pointing to the last element that is less than key. const_iterator less( const Key& key ) const { const_iterator lower = self::lower_bound(key); if(lower == self::begin()) { return self::end(); } else { lower--; return lower; } } const_iterator less_or_max( const Key& key ) const { const_iterator less = self::less(key); if(less == self::end()) { return self::max(); } else { return less; } } const_iterator max() const { const_iterator max = self::end(); if(self::size() > 0) { max--; } return max; } const_iterator min() const { return self::begin(); } };