mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 22:59:47 +08:00
Added interface move assignment.
This commit is contained in:
parent
6b165aee54
commit
96ce602874
@ -49,7 +49,6 @@ SOFTWARE.
|
||||
#include "debug_count.h"
|
||||
#include "algorithm.h"
|
||||
#include "type_traits.h"
|
||||
#include "parameter_type.h"
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL)
|
||||
#include <initializer_list>
|
||||
@ -1948,6 +1947,29 @@ namespace etl
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
//*************************************************************************
|
||||
/// Move assignment operator.
|
||||
//*************************************************************************
|
||||
ideque& operator =(ideque&& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
clear();
|
||||
iterator itr = rhs.begin();
|
||||
while (itr != rhs.end())
|
||||
{
|
||||
push_back(std::move(*itr));
|
||||
++itr;
|
||||
}
|
||||
|
||||
rhs.initialise();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ETL_IDEQUE_REPAIR_ENABLE
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
|
||||
@ -240,6 +240,40 @@ namespace
|
||||
CHECK(std::equal(deque1.begin(), deque1.end(), deque2.begin()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_move_assignment_interface)
|
||||
{
|
||||
const size_t SIZE = 10U;
|
||||
typedef etl::deque<std::unique_ptr<uint32_t>, SIZE> Data;
|
||||
typedef etl::ideque<std::unique_ptr<uint32_t>> IData;
|
||||
|
||||
std::unique_ptr<uint32_t> p1(new uint32_t(1U));
|
||||
std::unique_ptr<uint32_t> p2(new uint32_t(2U));
|
||||
std::unique_ptr<uint32_t> p3(new uint32_t(3U));
|
||||
std::unique_ptr<uint32_t> p4(new uint32_t(4U));
|
||||
|
||||
Data deque1;
|
||||
deque1.push_back(std::move(p1));
|
||||
deque1.push_back(std::move(p2));
|
||||
deque1.push_back(std::move(p3));
|
||||
deque1.push_back(std::move(p4));
|
||||
|
||||
Data deque2;
|
||||
|
||||
IData& ideque1 = deque1;
|
||||
IData& ideque2 = deque2;
|
||||
|
||||
ideque2 = std::move(ideque1);
|
||||
|
||||
CHECK_EQUAL(0U, deque1.size());
|
||||
CHECK_EQUAL(4U, deque2.size());
|
||||
|
||||
CHECK_EQUAL(1U, *deque2[0]);
|
||||
CHECK_EQUAL(2U, *deque2[1]);
|
||||
CHECK_EQUAL(3U, *deque2[2]);
|
||||
CHECK_EQUAL(4U, *deque2[3]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_self_assignment)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user