solve lvalue problem in container shift; refs #7
This commit is contained in:
@@ -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
|
||||
//@}
|
||||
//@}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user