my initial idea does not work - full copy on shift in, reference on shift out; refs #6

master
Marc Wäckerlin 11 years ago
parent 3008592ecb
commit 7cd37fbec7
  1. 26
      src/mrw/deque.hxx
  2. 12
      src/mrw/list.hxx
  3. 33
      src/mrw/map.hxx
  4. 28
      src/mrw/multimap.hxx
  5. 26
      src/mrw/multiset.hxx
  6. 29
      src/mrw/set.hxx
  7. 26
      src/mrw/vector.hxx

@ -49,21 +49,12 @@
@param o a value to be inserted into deque @c l
@pre \#include <mrw/deque.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
template <typename T, typename A>
std::deque<T, A> operator<<(std::deque<T, A> l, const T& o)
throw(std::bad_exception) {
l.push_back(o);
return l;
}
#else
template <typename T, typename A>
std::deque<T, A>&& operator<<(std::deque<T, A>&& l, const T& o)
throw(std::bad_exception) {
l.push_back(o);
return l;
}
#endif
/** @brief extract the first value of a deque
@ -83,22 +74,8 @@ template <typename T, typename A>
shortened by the shifted element
@pre \#include <mrw/deque.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
template <typename T, typename A>
std::deque<T, A> operator>>(std::deque<T, A> l, T& o)
throw(std::exception) {
typename std::deque<T, A>::iterator it(l.begin());
if (it==l.end())
throw mrw::length_error(std::string(__FILE__ ":")+__LINE__+
": std::deque<>& operator>>(std::deque<>&, T&),"
" deque is empty");
o = *it;
l.erase(it);
return l;
}
#else
template <typename T, typename A>
std::deque<T, A>&& operator>>(std::deque<T, A>&& l, T& o)
std::deque<T, A>& operator>>(std::deque<T, A>& l, T& o)
throw(std::exception) {
typename std::deque<T, A>::iterator it(l.begin());
if (it==l.end())
@ -109,7 +86,6 @@ template <typename T, typename A>
l.erase(it);
return l;
}
#endif
//@}
//@}

@ -67,14 +67,8 @@
@param o a value to be inserted into list @c l
@pre \#include <mrw/list.hxx>
*/
// template <typename T, typename A, typename FROM>
// std::list<T, A>& operator<<(std::list<T, A>& l, const FROM& o)
// throw(std::bad_exception) {
// l.push_back(T(o));
// return l;
// }
template <typename T, typename A>
std::list<T, A>& operator<<(std::list<T, A>& l, const T& o)
std::list<T, A> operator<<(std::list<T, A> l, const T& o)
throw(std::bad_exception) {
l.push_back(o);
return l;
@ -91,8 +85,8 @@ template <typename T, typename A>
@param o a value to be inserted into list @c l
@pre \#include <mrw/list.hxx> */
template <typename T, typename A>
std::list<T, A>& operator<<(std::list<T, A>& l,
const char *const o)
std::list<T, A> operator<<(std::list<T, A> l,
const char *const o)
throw(std::bad_exception) {
l.push_back(T(o));
return l;

@ -51,7 +51,6 @@
@param o a value to be inserted into map @c l
@pre \#include <mrw/map.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
template <typename K, typename T, class C, typename A>
std::map<K, T, C, A> operator<<(std::map<K, T, C, A> l,
const std::pair<K, T>& o)
@ -63,19 +62,6 @@ template <typename K, typename T, class C, typename A>
"map element already exists");
return l;
}
#else
template <typename K, typename T, class C, typename A>
std::map<K, T, C, A>&& operator<<(std::map<K, T, C, A>&& l,
const std::pair<K, T>& o)
throw(std::exception) {
if (!l.insert(o).second)
throw mrw::invalid_argument(std::string(__FILE__ ":")+__LINE__+
": std::map<>&"
" operator<<(std::map<>&, const T&),"
"map element already exists");
return l;
}
#endif
/** @brief extract the first value of a map
@ -96,9 +82,9 @@ template <typename K, typename T, class C, typename A>
shortened by the shifted element
@pre \#include <mrw/map.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
template <typename K, typename T, class C, typename A>
std::map<K, T, C, A> operator>>(std::map<K, T, C, A> l, std::pair<K, T>& o)
std::map<K, T, C, A>& operator>>(std::map<K, T, C, A>& l,
std::pair<K, T>& o)
throw(std::exception) {
typename std::map<K, T, C, A>::iterator it(l.begin());
if (it==l.end())
@ -109,21 +95,6 @@ template <typename K, typename T, class C, typename A>
l.erase(it);
return l;
}
#else
template <typename K, typename T, class C, typename A>
std::map<K, T, C, A>&& operator>>(std::map<K, T, C, A>&& l,
std::pair<K, T>& o)
throw(std::exception) {
typename std::map<K, T, C, A>::iterator it(l.begin());
if (it==l.end())
throw mrw::length_error(std::string(__FILE__ ":")+__LINE__+
": std::map<>& operator>>(std::map<>&, T&),"
" map is empty");
o = *it;
l.erase(it);
return l;
}
#endif
//@}
//@}

@ -51,7 +51,6 @@
@param o a value to be inserted into multimap @c l
@pre \#include <mrw/multimap.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
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)
@ -59,15 +58,6 @@ template <typename K, typename T, class C, typename A>
l.insert(o);
return l;
}
#else
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)
throw(std::bad_exception) {
l.insert(o);
return l;
}
#endif
/** @brief extract the first value of a multimap
@ -88,9 +78,8 @@ template <typename K, typename T, class C, typename A>&&
shortened by the shifted element
@pre \#include <mrw/multimap.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
template <typename K, typename T, class C, typename A>
std::multimap<K, T, C, A> operator>>(std::multimap<K, T, C, A> l,
std::multimap<K, T, C, A>& operator>>(std::multimap<K, T, C, A>& l,
std::pair<K, T>& o)
throw(std::exception) {
typename std::multimap<K, T, C, A>::iterator it(l.begin());
@ -102,21 +91,6 @@ template <typename K, typename T, class C, typename A>
l.erase(it);
return l;
}
#else
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)
throw(std::exception) {
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
//@}
//@}

@ -49,21 +49,12 @@
@param o a value to be inserted into multiset @c l
@pre \#include <mrw/multiset.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
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;
}
#else
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;
}
#endif
/** @brief extract the first value of a multiset
@ -83,22 +74,8 @@ template <typename T, class C, typename A>
shortened by the shifted element
@pre \#include <mrw/multiset.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
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>>,"
" multiset is empty");
o = *it;
l.erase(it);
return l;
}
#else
template <typename T, class C, typename A>
std::multiset<T, C, A>&& operator>>(std::multiset<T, C, A>&& l, T& o)
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())
@ -109,7 +86,6 @@ template <typename T, class C, typename A>
l.erase(it);
return l;
}
#endif
//@}
//@}

@ -50,7 +50,6 @@
@param o a value to be inserted into set @c l
@pre \#include <mrw/set.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
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) {
@ -60,17 +59,6 @@ template <typename T, class C, typename A>
"set element already exists");
return l;
}
#else
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<<, "
"set element already exists");
return l;
}
#endif
/** @brief extract the first value of a set
@ -90,22 +78,8 @@ template <typename T, class C, typename A>
shortened by the shifted element
@pre \#include <mrw/set.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
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>>,"
" set is empty");
o = *it;
l.erase(it);
return l;
}
#else
template <typename T, class C, typename A>
std::set<T, C, A> operator>>(std::set<T, C, A> l, T& o)
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())
@ -116,7 +90,6 @@ template <typename T, class C, typename A>
l.erase(it);
return l;
}
#endif
//@}
//@}

@ -49,21 +49,12 @@
@param o a value to be inserted into vector @c l
@pre \#include <mrw/vector.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
template <typename T, typename A>
std::vector<T, A> operator<<(std::vector<T, A> l, const T& o)
throw(std::bad_exception) {
l.push_back(o);
return l;
}
#else
template <typename T, typename A>
std::vector<T, A>&& operator<<(std::vector<T, A>&& l, const T& o)
throw(std::bad_exception) {
l.push_back(o);
return l;
}
#endif
/** @brief extract the first value of a vector
@ -83,22 +74,8 @@ template <typename T, typename A>
shortened by the shifted element
@pre \#include <mrw/vector.hxx>
*/
#ifdef MRW__OLD_PRE11_COMPILER
template <typename T, typename A>
std::vector<T, A> operator>>(std::vector<T, A> l, T& o)
throw(std::exception) {
typename std::vector<T, A>::iterator it(l.begin());
if (it==l.end())
throw mrw::length_error(std::string(__FILE__ ":")+__LINE__+
": std::vector<>& operator>>(std::vector<>&, T&),"
" vector is empty");
o = *it;
l.erase(it);
return l;
}
#else
template <typename T, typename A>
std::vector<T, A>&& operator>>(std::vector<T, A>&& l, T& o)
std::vector<T, A>& operator>>(std::vector<T, A>& l, T& o)
throw(std::exception) {
typename std::vector<T, A>::iterator it(l.begin());
if (it==l.end())
@ -109,7 +86,6 @@ std::vector<T, A>&& operator>>(std::vector<T, A>&& l, T& o)
l.erase(it);
return l;
}
#endif
//@}
//@}

Loading…
Cancel
Save