mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 22:59:47 +08:00
Added move constructor and assignment operator
This commit is contained in:
parent
338164d871
commit
ca81392075
@ -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.
|
||||
//*************************************************************************
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user