Replaced post increment with pre increment

This commit is contained in:
John Wellbelove 2022-02-03 17:16:26 +00:00
parent 791aa97885
commit 87fe3eec2d
17 changed files with 147 additions and 49 deletions

View File

@ -1298,7 +1298,8 @@ namespace etl
{
while (first != last)
{
etl::pop_heap(first, last--);
etl::pop_heap(first, last);
--last;
}
}
@ -1308,7 +1309,8 @@ namespace etl
{
while (first != last)
{
etl::pop_heap(first, last--, compare);
etl::pop_heap(first, last, compare);
--last;
}
}

View File

@ -1437,7 +1437,8 @@ namespace etl
// Create copy.
for (size_t i = 0UL; i < n_create_copy; ++i)
{
create_element_front(*from--);
create_element_front(*from);
--from;
}
// Move old.

View File

@ -978,11 +978,14 @@ namespace etl
etl::iflat_map<TKey, TMapped, TKeyCompare>::iterator first = rhs.begin();
etl::iflat_map<TKey, TMapped, TKeyCompare>::iterator last = rhs.end();
// Add all of the elements.
// Move all of the elements.
while (first != last)
{
typename etl::iflat_map<TKey, TMapped, TKeyCompare>::iterator temp = first;
++temp;
this->insert(etl::move(*first));
++first;
first = temp;
}
}
}

View File

@ -862,11 +862,14 @@ namespace etl
etl::iflat_multimap<TKey, TMapped, TKeyCompare>::iterator first = rhs.begin();
etl::iflat_multimap<TKey, TMapped, TKeyCompare>::iterator last = rhs.end();
// Add all of the elements.
// Move all of the elements.
while (first != last)
{
typename etl::iflat_multimap<TKey, TMapped, TKeyCompare>::iterator temp = first;
++temp;
this->insert(etl::move(*first));
++first;
first = temp;
}
}
}

View File

@ -815,11 +815,14 @@ namespace etl
etl::iflat_multiset<T, TKeyCompare>::iterator first = rhs.begin();
etl::iflat_multiset<T, TKeyCompare>::iterator last = rhs.end();
// Add all of the elements.
// Move all of the elements.
while (first != last)
{
typename etl::iflat_multiset<T, TKeyCompare>::iterator temp = first;
++temp;
this->insert(etl::move(*first));
++first;
first = temp;
}
}
}

View File

@ -902,11 +902,14 @@ namespace etl
etl::iflat_set<T, TKeyCompare>::iterator first = rhs.begin();
etl::iflat_set<T, TKeyCompare>::iterator last = rhs.end();
// Add all of the elements.
// Move all of the elements.
while (first != last)
{
typename etl::iflat_set<T, TKeyCompare>::iterator temp = first;
++temp;
this->insert(etl::move(*first));
++first;
first = temp;
}
}
}

View File

@ -2632,8 +2632,11 @@ namespace etl
while (from != other.end())
{
typename etl::imap<TKey, TValue, TCompare>::iterator temp = from;
++temp;
this->insert(etl::move(*from));
++from;
from = temp;
}
}
}
@ -2700,8 +2703,11 @@ namespace etl
while (from != rhs.end())
{
typename etl::imap<TKey, TValue, TCompare>::iterator temp = from;
++temp;
this->insert(etl::move(*from));
++from;
from = temp;
}
}

View File

@ -2355,8 +2355,11 @@ namespace etl
while (from != other.end())
{
typename etl::imultimap<TKey, TValue, TCompare>::iterator temp = from;
++temp;
this->insert(etl::move(*from));
++from;
from = temp;
}
}
}
@ -2420,8 +2423,11 @@ namespace etl
while (from != rhs.end())
{
typename etl::imultimap<TKey, TValue, TCompare>::iterator temp = from;
++temp;
this->insert(etl::move(*from));
++from;
from = temp;
}
}

View File

@ -939,6 +939,13 @@ namespace etl
}
private:
// Convert to an iterator.
imultiset::iterator to_iterator() const
{
return imultiset::iterator(const_cast<imultiset&>(*p_multiset), const_cast<Node*>(p_node));
}
// Pointer to multiset associated with this iterator
const imultiset* p_multiset;
@ -1171,7 +1178,7 @@ namespace etl
// Increment count for each node removed
++d;
// Remove node using the other erase method
(void)erase(lower++);
lower = erase(lower);
}
// Return the total count erased
@ -1192,7 +1199,7 @@ namespace etl
// Increment count for each node removed
++d;
// Remove node using the other erase method
(void)erase(lower++);
lower = erase(lower);
}
// Return the total count erased
@ -1208,10 +1215,10 @@ namespace etl
iterator next;
while (first != last)
{
next = erase(first++);
first = erase(first);
}
return next;
return last.to_iterator();
}
//*********************************************************************
@ -1336,7 +1343,8 @@ namespace etl
{
while (first != last)
{
insert(*first++);
insert(*first);
++first;
}
}
@ -1447,7 +1455,11 @@ namespace etl
while (from != rhs.end())
{
insert(etl::move(*from++));
typename etl::imultiset<TKey, TCompare>::iterator temp = from;
++temp;
this->insert(etl::move(*from));
from = temp;
}
}
@ -2326,7 +2338,11 @@ namespace etl
while (from != other.end())
{
this->insert(etl::move(*from++));
typename etl::imultiset<TKey, TCompare>::iterator temp = from;
++temp;
this->insert(etl::move(*from));
from = temp;
}
}
}
@ -2392,7 +2408,8 @@ namespace etl
while (from != rhs.end())
{
this->insert(etl::move(*from++));
this->insert(etl::move(*from));
++from;
}
}

View File

@ -774,6 +774,13 @@ namespace etl
}
private:
// Convert to an iterator.
iset::iterator to_iterator() const
{
return iset::iterator(const_cast<iset&>(*p_set), const_cast<Node*>(p_node));
}
// Pointer to set associated with this iterator
const iset* p_set;
@ -814,7 +821,11 @@ namespace etl
while (from != rhs.end())
{
insert(etl::move(*from++));
typename etl::iset<TKey, TCompare>::iterator temp = from;
++temp;
this->insert(etl::move(*from));
from = temp;
}
}
@ -1047,13 +1058,12 @@ namespace etl
//*************************************************************************
iterator erase(const_iterator first, const_iterator last)
{
iterator next;
while (first != last)
{
next = erase(first++);
first = erase(first);
}
return next;
return last.to_iterator();
}
//*********************************************************************
@ -1204,7 +1214,8 @@ namespace etl
{
while (first != last)
{
insert(*first++);
insert(*first);
++first;
}
}
@ -2523,13 +2534,19 @@ namespace etl
set(set&& other)
: etl::iset<TKey, TCompare>(node_pool, MAX_SIZE)
{
int count = 0;
if (this != &other)
{
typename etl::iset<TKey, TCompare>::iterator from = other.begin();
while (from != other.end())
{
this->insert(etl::move(*from++));
typename etl::iset<TKey, TCompare>::iterator temp = from;
++temp;
this->insert(etl::move(*from));
from = temp;
}
}
}
@ -2594,7 +2611,11 @@ namespace etl
while (from != rhs.end())
{
this->insert(etl::move(*from++));
typename etl::iset<TKey, TCompare>::iterator temp = from;
++temp;
this->insert(etl::move(*from));
from = temp;
}
}

View File

@ -132,7 +132,8 @@ namespace etl
{
while (first != last)
{
add(*first++);
add(*first);
++first;
}
}

View File

@ -745,7 +745,8 @@ namespace etl
while (first_ != last_)
{
insert(*first_++);
insert(*first_);
++first_;
}
}
@ -937,7 +938,8 @@ namespace etl
{
while (first_ != last_)
{
insert(*first_++);
insert(*first_);
++first_;
}
}
@ -1359,7 +1361,10 @@ namespace etl
{
while (first != last)
{
insert(etl::move(*first++));
iterator temp = first;
++temp;
insert(etl::move(*first));
first = temp;
}
}
#endif

View File

@ -633,7 +633,8 @@ namespace etl
while (first_ != last_)
{
insert(*first_++);
insert(*first_);
++first_;
}
}
@ -811,7 +812,8 @@ namespace etl
{
while (first_ != last_)
{
insert(*first_++);
insert(*first_);
++first_;
}
}
@ -1265,7 +1267,10 @@ namespace etl
{
while (first != last)
{
insert(etl::move(*first++));
iterator temp = first;
++temp;
insert(etl::move(*first));
first = temp;
}
}
#endif

View File

@ -629,7 +629,8 @@ namespace etl
while (first_ != last_)
{
insert(*first_++);
insert(*first_);
++first_;
}
}
@ -794,7 +795,8 @@ namespace etl
{
while (first_ != last_)
{
insert(*first_++);
insert(*first_);
++first_;
}
}
@ -1249,7 +1251,10 @@ namespace etl
{
while (first != last)
{
insert(etl::move(*first++));
iterator temp = first;
++temp;
insert(etl::move(*first));
first = temp;
}
}
#endif

View File

@ -630,7 +630,8 @@ namespace etl
while (first_ != last_)
{
insert(*first_++);
insert(*first_);
++first_;
}
}
@ -816,7 +817,8 @@ namespace etl
{
while (first_ != last_)
{
insert(*first_++);
insert(*first_);
++first_;
}
}
@ -1249,7 +1251,10 @@ namespace etl
while (first != last)
{
insert(etl::move(*first++));
iterator temp = first;
++temp;
insert(etl::move(*first));
first = temp;
}
}
#endif

View File

@ -132,7 +132,8 @@ namespace etl
{
while (first != last)
{
add(*first++);
add(*first);
++first;
}
}

View File

@ -45,12 +45,13 @@ static const size_t MAX_SIZE = 10UL;
#define TEST_GREATER_THAN
#ifdef TEST_GREATER_THAN
using Data = etl::set<int, MAX_SIZE, std::greater<int>>;
using IData = etl::iset<int, std::greater<int>>;
using Compare_Data = std::set<int, std::greater<int>>;
using Data = etl::set<int, MAX_SIZE, std::greater<int>>;
using IData = etl::iset<int, std::greater<int>>;
using Compare_Data = std::set<int, std::greater<int>>;
#else
using Data = etl::set<int, MAX_SIZE, std::less<int>>;
using Compare_Data = std::set<int, std::less<int>>;
using Data = etl::set<int, MAX_SIZE, std::less<int>>;
using IData = etl::iset<int, std::less<int>>;
using Compare_Data = std::set<int, std::less<int>>;
#endif
using ItemM = TestDataM<int>;
@ -97,6 +98,11 @@ namespace
return (lhs < rhs.k);
}
bool operator <(const Key& lhs, const Key& rhs)
{
return (lhs.k < rhs.k);
}
SUITE(test_set)
{
//*************************************************************************
@ -244,6 +250,11 @@ namespace
CHECK_EQUAL(2, ItemM(2).value);
CHECK_EQUAL(3, ItemM(3).value);
CHECK_EQUAL(4, ItemM(4).value);
CHECK(data2.find(ItemM(1)) != data2.end());
CHECK(data2.find(ItemM(2)) != data2.end());
CHECK(data2.find(ItemM(3)) != data2.end());
CHECK(data2.find(ItemM(4)) != data2.end());
}
//*************************************************************************