Added move constructor and assignment operator

This commit is contained in:
John Wellbelove 2018-12-29 20:56:37 +00:00
parent 338164d871
commit ca81392075

View File

@ -1289,7 +1289,10 @@ namespace etl
vector(const vector& other)
: etl::ivector<T*>(reinterpret_cast<T**>(&buffer), MAX_SIZE)
{
this->assign(other.begin(), other.end());
if (this != &other)
{
this->assign(other.begin(), other.end());
}
}
//*************************************************************************
@ -1305,6 +1308,50 @@ namespace etl
return *this;
}
#if ETL_CPP11_SUPPORTED
//*************************************************************************
/// Move constructor.
//*************************************************************************
vector(vector&& other)
: etl::ivector<T*>(reinterpret_cast<T**>(&buffer), MAX_SIZE)
{
if (this != &other)
{
this->initialise();
typename etl::ivector<T>::iterator itr = other.begin();
while (itr != other.end())
{
this->push_back(std::move(*itr));
++itr;
}
other.initialise();
}
}
//*************************************************************************
/// Assignment operator.
//*************************************************************************
vector& operator = (vector&& rhs)
{
if (&rhs != this)
{
this->clear();
typename etl::ivector<T>::iterator itr = rhs.begin();
while (itr != rhs.end())
{
this->push_back(std::move(*itr));
++itr;
}
rhs.initialise();
}
return *this;
}
#endif
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************