C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

122 lines
3.2 KiB

/** @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__MULTIMAP__HPP__
#define __MRW__MULTIMAP__HPP__
#include <map>
#include <mrw/checkcxx11.hxx>
#include <mrw/exception.hxx>
#include <mrw/string.hxx>
/** @addtogroup StdExtSTL
*/
//@{
/** @defgroup StdExtmultimap multimap
*/
//@{
/** @brief insert a value in a multimap
@code
std::multimap<int, std::string> test;
test<<std::make_pair(1, std::string("one"))
<<std::make_pair(2, std::string("two"));
@endcode
@throw mrw::invalid_argument, if element is already in multimap
@param l a multimap of values
@param o a value to be inserted into multimap @c l
@pre \#include <mrw/multimap.hxx>
*/
template <typename K, typename T, class C, typename A>
std::multimap<K, T, C, A>& operator<<(std::multimap<K, T, C, A>& l,
const std::pair<K, T>& o)
{
l.insert(o);
return l;
}
/** @brief insert a value in a multimap
Makes a copy and returns the copy.
@code
std::multimap<int, std::string>()
<<std::make_pair(1, std::string("one"))
<<std::make_pair(2, std::string("two"));
@endcode
@throw mrw::invalid_argument, if element is already in multimap
@param l a multimap of values
@param o a value to be inserted into multimap @c l
@pre \#include <mrw/multimap.hxx>
*/
template <typename K, typename T, class C, typename A>
std::multimap<K, T, C, A> operator<<(const std::multimap<K, T, C, A>& l,
const std::pair<K, T>& o)
{
std::multimap<K, T, C, A> copy(l);
copy.insert(o);
return copy;
}
/** @brief extract the first value of a multimap
@code
std::multimap<int, std::string> test;
test<<std::make_pair(1, std::string("one"))
<<std::make_pair(2, std::string("two"));
std::pair<int, std::string> i1, i2;
test>>i1>>i2;
// now: i1==(1, "one") i2==(2, "two") test=={}
@endcode
@param l a multimap of values
@param o a value to be extracted from multimap @c l
@throw mrw::length_error, if multimap was empty on entry
@note when something is extracted from a multimap, it is removed
from the multimap, that means after every shift the multimap is
shortened by the shifted element
@pre \#include <mrw/multimap.hxx>
*/
template <typename K, typename T, class C, typename A>
std::multimap<K, T, C, A>& operator>>(std::multimap<K, T, C, A>& l,
std::pair<K, T>& o)
{
typename std::multimap<K, T, C, A>::iterator it(l.begin());
if (it==l.end())
throw mrw::length_error(std::string(__FILE__ ":")+__LINE__+
": std::multimap<>::operator>>,"
" multimap is empty");
o = *it;
l.erase(it);
return l;
}
//@}
//@}
#endif