本文整理汇总了C++中forward_list::before_begin方法的典型用法代码示例。如果您正苦于以下问题:C++ forward_list::before_begin方法的具体用法?C++ forward_list::before_begin怎么用?C++ forward_list::before_begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forward_list
的用法示例。
在下文中一共展示了forward_list::before_begin方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertString
void insertString(forward_list<string> &strflst, const string &search, const string &str)
{
auto prev = strflst.before_begin();
auto curr = strflst.begin();
if (!strflst.empty())
{
bool flag = false;
while(curr != strflst.end())
{
if (*curr == search)
{
curr = strflst.insert_after(curr, str);
flag = true;
}
else
{
prev = curr++;
}
}
if (!flag)
{
strflst.insert_after(prev, str);
}
}
}
示例2: insertAfterStr
void insertAfterStr(forward_list<string> &flist, string flag, string insert){
auto pre = flist.before_begin();
auto item = flist.begin();
while (item != flist.end() && *item != flag)
pre++, item++;
item == flist.end() ? flist.insert_after(pre, insert) : flist.insert_after(item, insert);
}
示例3: updateSounds
void updateSounds() {
auto prevIt = sounds.before_begin();
for (auto it = sounds.begin(); it != sounds.end(); it++) {
if (it->getStatus() == sf::Sound::Stopped) {
sounds.erase_after(prevIt);
it = prevIt;
}
else prevIt = it;
}
}
示例4: remove_evens_and_double_odds
void remove_evens_and_double_odds(forward_list<int>& data) {
for (auto cur = data.begin(), prev = data.before_begin(); cur != data.end(); ) {
if (*cur & 0x1)
cur = data.insert_after(prev, *cur),
advance(prev, 2),
advance(cur, 2);
else
cur = data.erase_after(prev);
}
}
示例5: insertWord
void insertWord(forward_list<string> &forList,
const string &str1,const string &str2)
{
auto prev = forList.before_begin();
for(auto i=forList.begin();i != forList.end();prev=i,++i)
if(*i == str1){
forList.insert_after(i,str2);
return ;
}
forList.insert_after(prev,str2);
}
示例6: func
forward_list<string> func(forward_list<string> &il, string s1, string s2) {
auto iter = il.begin();
auto prev = il.before_begin();
for (; iter != il.end(); prev = iter++)
if (*iter == s1)
break;
if (iter == il.end())
il.insert_after(prev, s2);
else
il.insert_after(iter, s2);
return il;
}
示例7: insertString
void insertString(forward_list<string>& fls,string target,string insertval){
auto cur=fls.begin();
auto prev=fls.before_begin();
while(cur!=fls.end()&&*cur!=target) {
prev=cur;
++cur;
}
if(cur!=fls.end())
fls.insert_after(cur,insertval);
else{
fls.insert_after(prev,insertval);
}
}
示例8: find_and_insert
void find_and_insert(forward_list<string> &list, string const& to_find, string const& to_add)
{
auto prev = list.before_begin();
for (auto curr = list.begin(); curr != list.end(); prev = curr++)
{
if (*curr == to_find)
{
list.insert_after(curr, to_add);
return;
}
}
list.insert_after(prev, to_add);
}
示例9: func
void func(forward_list<string> &flist, const string s1, const string s2)
{
auto before = flist.before_begin();
auto curr = flist.begin();
while(curr!=flist.end()) {
if(*curr == s1){
flist.insert_after(curr, s2);
return;
}else{
curr++;
}
}
flist.insert_after(curr, s2);
}
示例10: insereInfoAtPosit
void insereInfoAtPosit(forward_list<T1>& maListeOriginale, int laPosition, T2 nouvelleInfo) throw (PrecondVioleeExcep) {
// version itérative
// itérateur positionné sur la postion avant le premier élément de la liste
// -> il faut être sur le précédent de laPosition pour fair l'insertion après !!
auto it = maListeOriginale.before_begin();
int positionCourante = 1;
// tantque l'on a pas atteint laPosition et que l'on est pas à la fin de la liste
while ((positionCourante < laPosition) && (it != maListeOriginale.end())) {
positionCourante++;
// avancer dans la liste sur l'itérateur
++it;
}
if (it != maListeOriginale.end()) { // si on a accès à laPosition
// insérer après l'élément pointé par l'itérateur
it = maListeOriginale.insert_after(it, nouvelleInfo);
} else { // sinon on lève une exception
throw PrecondVioleeExcep("Insertion imposible à l'indice " + to_string(laPosition));
}
}
示例11: replace
void replace(forward_list<string> &sflst, const string &str1, const string &str2)
{
int flag = 0;
auto prev = sflst.before_begin();
auto curr = sflst.begin();
auto end = sflst.end();
while (curr != end)
if (*curr == str1)
{
curr = sflst.emplace_after(curr, str2);
flag = 1;
}
else
{
prev = curr;
++curr;
}
if (!flag)
sflst.insert_after(prev, str2);
}
示例12: FindStringInsertString
void FindStringInsertString(forward_list<string>& strlist, string strtofind, string strtoinsert)
{
forward_list<string>::iterator current = strlist.begin();
forward_list<string>::iterator pre = strlist.before_begin();
bool findflag = false;
while (current != strlist.end())
{
if (*current == strtofind)
{
current = strlist.insert_after(current,strtoinsert);
findflag = true;
}
pre = current;
current++;
}
if (!findflag)
{
strlist.insert_after(pre, strtoinsert);
}
return;
}