/** @file

    $Id$

    $Date$
    $Author$

    @copy © Marc Wäckerlin
    @license LGPL, see file <a href="license.html">COPYING</a>

    $Log$
    Revision 1.4  2005/11/29 12:39:42  marc
    make it compilable with gcc 4.0.2 and newer doxygen

    Revision 1.3  2005/04/07 20:48:20  marc
    docu: new doxygen, new grouping

    Revision 1.2  2004/12/20 07:40:36  marc
    documentation improved, new grouping

    Revision 1.1  2004/10/07 09:31:30  marc
    new feature


*/
#ifndef __MRW__MULTISET__HPP__
#define __MRW__MULTISET__HPP__

#include <set>
#include <mrw/exception.hpp>
#include <mrw/string.hpp>

/** @addtogroup StdExtSTL
 */
//@{
/** @defgroup StdExtmultiset multiset
 */
//@{

/** @brief insert a value in a multiset

    @code
    std::multiset<int> test;
    test<<1<<2<<3<<4<<5<<6<<7<<8;
    @endcode

    @param l a multiset of values
    @param o a value to be inserted into multiset @c l
    @pre \#include <mrw/multiset.hpp>
*/
template <typename T, class C, typename A>
std::multiset<T, C, A>& operator<<(std::multiset<T, C, A>& l, const T& o) throw(std::bad_exception) {
  l.insert(o);
  return l;
}

/** @brief extract the first value of a multiset

    @code
    std::multiset<int> test;
    test<<1<<2<<3<<4<<5<<6<<7<<8;
    int i1(0), i2(0), i3(0), i4(0);
    test>>i1>>i2>>i3>>i4;
    // now: i1==1 i2==2 i3==3 i4==4 test=={5, 6, 7, 8}
    @endcode

    @param l a multiset of values
    @param o a value to be extracted from multiset @c l
    @throw mrw::length_error, if set was empty on entry
    @note when something is extracted from a multiset, it is removed
    from the multiset, that means after every shift the multiset is
    shortened by the shifted element
    @pre \#include <mrw/multiset.hpp>
*/
template <typename T, class C, typename A>
std::multiset<T, C, A>& operator>>(std::multiset<T, C, A>& l, T& o) throw(std::exception) {
  typename std::multiset<T, C, A>::iterator it(l.begin());
  if (it==l.end())
    throw mrw::length_error(std::string(__FILE__ ":")+__LINE__+
                            ": std::multiset<>& operator>>(std::multiset<>&, T&),"
                            " multiset is empty");
  o = *it;
  l.erase(it);
  return l;
}

//@}
//@}

#endif