本文整理汇总了C++中std::forward_list::before_begin方法的典型用法代码示例。如果您正苦于以下问题:C++ forward_list::before_begin方法的具体用法?C++ forward_list::before_begin怎么用?C++ forward_list::before_begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::forward_list
的用法示例。
在下文中一共展示了forward_list::before_begin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: InsertString
void InsertString(std::forward_list<std::string> &s, const std::string &s1, const std::string &s2)
{
std::forward_list<std::string>::iterator a, prev = s.before_begin();
for (a = s.begin(); a != s.end(); ++a, ++prev) {
if (*a == s1) {
s.insert_after(a, s2);
return;
}
}
s.insert_after(prev, s2);
}
示例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: operator
inline void operator () (Args... args)
{
if(slots.empty())
return;
auto it = slots.begin(), end = slots.end();
auto prev = slots.before_begin();
while(it != end)
{
try
{
(*it)(args...);
}
catch(slot_remove)
{
slots.erase_after(prev);
it = prev;
}
prev = it;
++it;
}
}