/** @file
$ Id $
$ Date $
$ Author $
@ copy & copy ; Marc W & auml ; ckerlin
@ license LGPL , see file < a href = " license.html " > COPYING < / a >
$ Log $
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__SET__HPP__
# define __MRW__SET__HPP__
# include <set>
# include <mrw/exception.hpp>
# include <mrw/string.hpp>
/** @addtogroup StdExt
*/
//@{
/** @addtogroup StdExtSTL
*/
//@{
/** @defgroup StdExtset set
*/
//@{
/** @brief insert a value in a set
@ code
std : : set < int > test ;
test < < 1 < < 2 < < 3 < < 4 < < 5 < < 6 < < 7 < < 8 ;
@ endcode
@ throw mrw : : invalid_argument , if element is already in set
@ param l a set of values
@ param o a value to be inserted into set @ c l
@ pre # include < mrw / set . hpp >
*/
template < typename T , class C , typename A >
std : : set < T , C , A > & operator < < ( std : : set < T , C , A > & l , const T & o )
throw ( std : : exception ) {
if ( ! l . insert ( o ) . second )
throw mrw : : invalid_argument ( std : : string ( __FILE__ " : " ) + __LINE__ +
" : std::set<>& "
" operator<<(std::set<>&, const T&), "
" set element already exists " ) ;
return l ;
}
/** @brief extract the first value of a set
@ code
std : : set < 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 set of values
@ param o a value to be extracted from set @ c l
@ throw mrw : : length_error , if set was empty on entry
@ note when something is extracted from a set , it is removed
from the set , that means after every shift the set is
shortened by the shifted element
@ pre # include < mrw / set . hpp >
*/
template < typename T , class C , typename A >
std : : set < T , C , A > & operator > > ( std : : set < T , C , A > & l , T & o )
throw ( std : : exception ) {
typename std : : set < T , C , A > : : iterator it ( l . begin ( ) ) ;
if ( it = = l . end ( ) )
throw mrw : : length_error ( std : : string ( __FILE__ " : " ) + __LINE__ +
" : std::set<>& operator>>(std::set<>&, T&), "
" set is empty " ) ;
o = * it ;
l . erase ( it ) ;
return l ;
}
//@}
//@}
//@}
# endif