solve lvalue problem in container shift; refs #7

This commit is contained in:
Marc Wäckerlin
2013-09-27 10:53:03 +00:00
parent 2763136313
commit 73ae395147
14 changed files with 452 additions and 139 deletions

View File

@@ -27,6 +27,7 @@
#define __MRW__VECTOR__HPP__
#include <vector>
#include <mrw/checkcxx11.hxx>
#include <mrw/exception.hxx>
#include <mrw/string.hxx>
@@ -48,11 +49,21 @@
@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) {
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
@@ -72,8 +83,10 @@ std::vector<T, A>& operator<<(std::vector<T, A>& l, const T& o) throw(std::bad_e
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) {
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__+
@@ -83,7 +96,20 @@ std::vector<T, A>& operator>>(std::vector<T, A>& l, T& o) throw(std::exception)
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
//@}
//@}