本文整理汇总了C++中std::forward_list::erase_after方法的典型用法代码示例。如果您正苦于以下问题:C++ forward_list::erase_after方法的具体用法?C++ forward_list::erase_after怎么用?C++ forward_list::erase_after使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::forward_list
的用法示例。
在下文中一共展示了forward_list::erase_after方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
inline int operator () (EArgs&&... args) // O(n)
{
if(slots.empty())
return default_return_value;
auto it = slots.cbegin(), end = slots.cend();
auto prev = slots.cbefore_begin();
while(it != end)
{
try
{
(it->second)(std::forward<EArgs>(args)...);
prev = it;
++it;
}
catch(slot_remove)
{
it = slots.erase_after(prev);
}
catch(signal_return e)
{
return e.get();
}
}
return default_return_value;
}
示例2: removeDupsNoBuffer
void removeDupsNoBuffer(std::forward_list<int>& l) {
if (l.empty())
return;
auto backtrack = l.before_begin();
while (std::next(backtrack) != l.end()) {
// Iterate and print values of the list
for (int n : l)
std::cout << n << '\t';
std::cout << std::endl;
auto prev = std::next(backtrack);
auto iter = std::next(prev);
//std::cout << " prev =" << *prev << ", iter=" << *iter << std::endl;
while (iter != l.end()) {
if (*iter == *std::next(backtrack))
iter = l.erase_after(prev);
else {
++prev;
++iter;
}
}
++backtrack;
}
}
示例3: removeDups2
void removeDups2(std::forward_list<int>& l) {
std::unordered_set<int> s;
auto prev = l.before_begin();
auto iter = l.begin();
while (iter != l.end()) {
if (s.find(*iter) != s.end()) {
iter = l.erase_after(prev);
} else {
s.insert(*iter);
++iter;
++prev;
}
}
}
示例4: disconnect
inline bool disconnect(connection_type con) // O(n)
{
auto it = slots.cbegin(), end = slots.cend();
auto prev = slots.cbefore_begin();
while(it != end)
{
if(it == con)
{
slots.erase_after(prev);
return true;
}
prev = it;
++it;
}
return false;
}
示例5: while
void LinkedListExercises::RemoveDuplicates2(std::forward_list<int>& rList)
{
std::unordered_map<int, int> my_table;
std::unordered_map<int, int>::const_iterator found_pos;
std::forward_list<int>::const_iterator it = rList.begin();
std::forward_list<int>::const_iterator prev_it = rList.begin();
while (it!=rList.end())
{
found_pos = my_table.find(*it);
if (found_pos != my_table.end())
{
it++; //Note: could use it = std::next(it)
rList.erase_after(prev_it);
}
else
{
my_table.insert(std::make_pair(*it, 1));
prev_it = it;
it++;
}
}
}
示例6: bad_erase_after_forward_list2
void bad_erase_after_forward_list2(std::forward_list<int> &FL) {
auto i3 = FL.cbegin(), i0 = i3++, i1 = i3++, i2 = i3++;
FL.erase_after(i0, i3);
*i1; // expected-warning{{Invalidated iterator accessed}}
*i2; // expected-warning{{Invalidated iterator accessed}}
}
示例7: good_erase_after_forward_list2
void good_erase_after_forward_list2(std::forward_list<int> &FL) {
auto i3 = FL.cbegin(), i0 = i3++, i1 = i3++, i2 = i3++;
FL.erase_after(i0, i3);
*i0; // no-warning
*i3; // no-warning
}
示例8: bad_erase_after_forward_list1
void bad_erase_after_forward_list1(std::forward_list<int> &FL) {
auto i1 = FL.cbegin(), i0 = i1++;
FL.erase_after(i0);
*i1; // expected-warning{{Invalidated iterator accessed}}
}
示例9: good_erase_after_forward_list1
void good_erase_after_forward_list1(std::forward_list<int> &FL) {
auto i2 = FL.cbegin(), i0 = i2++, i1 = i2++;
FL.erase_after(i0);
*i0; // no-warning
*i2; // no-warning
}