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. 10
      src/mrw/list.hxx
  3. 31
      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 @param o a value to be inserted into deque @c l
@pre \#include <mrw/deque.hxx> @pre \#include <mrw/deque.hxx>
*/ */
#ifdef MRW__OLD_PRE11_COMPILER
template <typename T, typename A> template <typename T, typename A>
std::deque<T, A> operator<<(std::deque<T, A> l, const T& o) std::deque<T, A> operator<<(std::deque<T, A> l, const T& o)
throw(std::bad_exception) { throw(std::bad_exception) {
l.push_back(o); l.push_back(o);
return l; 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 /** @brief extract the first value of a deque
@ -83,22 +74,8 @@ template <typename T, typename A>
shortened by the shifted element shortened by the shifted element
@pre \#include <mrw/deque.hxx> @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> 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) { throw(std::exception) {
typename std::deque<T, A>::iterator it(l.begin()); typename std::deque<T, A>::iterator it(l.begin());
if (it==l.end()) if (it==l.end())
@ -109,7 +86,6 @@ template <typename T, typename A>
l.erase(it); l.erase(it);
return l; return l;
} }
#endif
//@} //@}
//@} //@}

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

@ -51,7 +51,6 @@
@param o a value to be inserted into map @c l @param o a value to be inserted into map @c l
@pre \#include <mrw/map.hxx> @pre \#include <mrw/map.hxx>
*/ */
#ifdef MRW__OLD_PRE11_COMPILER
template <typename K, typename T, class C, typename A> template <typename K, typename T, class C, typename A>
std::map<K, T, C, A> operator<<(std::map<K, T, C, A> l, std::map<K, T, C, A> operator<<(std::map<K, T, C, A> l,
const std::pair<K, T>& o) const std::pair<K, T>& o)
@ -63,19 +62,6 @@ template <typename K, typename T, class C, typename A>
"map element already exists"); "map element already exists");
return l; 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 /** @brief extract the first value of a map
@ -96,22 +82,8 @@ template <typename K, typename T, class C, typename A>
shortened by the shifted element shortened by the shifted element
@pre \#include <mrw/map.hxx> @pre \#include <mrw/map.hxx>
*/ */
#ifdef MRW__OLD_PRE11_COMPILER
template <typename K, typename T, class C, typename A> 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,
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;
}
#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) std::pair<K, T>& o)
throw(std::exception) { throw(std::exception) {
typename std::map<K, T, C, A>::iterator it(l.begin()); typename std::map<K, T, C, A>::iterator it(l.begin());
@ -123,7 +95,6 @@ template <typename K, typename T, class C, typename A>
l.erase(it); l.erase(it);
return l; return l;
} }
#endif
//@} //@}
//@} //@}

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

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

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

Loading…
Cancel
Save