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

This commit is contained in:
Marc Wäckerlin
2013-10-02 14:44:55 +00:00
parent 3008592ecb
commit 7cd37fbec7
7 changed files with 10 additions and 170 deletions

View File

@@ -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,9 +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)
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())
@@ -96,20 +86,6 @@ std::vector<T, A> operator>>(std::vector<T, A> l, T& o)
l.erase(it);
return l;
}
#else
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;
}
#endif
//@}
//@}