<commit_before>//
//  ex9_31.cpp
//  Exercise 9.31
//
//  Created by pezy on 12/3/14.
//  Copyright (c) 2014 pezy. All rights reserved.
//
//  @Brief  The program on page 354 to remove even-valued elements and
//          duplicate odd ones will not work on a list or forward_list. Why?
//          Revise the program so that it works on these types as well.
//  @list   iter += 2; -> advance(iter, 2);
//

#include <iostream>
#include <list>

using std::cout;
using std::endl;
using std::list;
using std::advance;

int main()
{
    list<int> vi={0,1,2,3,4,5,6,7,8,9};
    auto iter=vi.begin();
    while(iter!=vi.end())
    {
        if(*iter%2)
        {
            iter=vi.insert(iter, *iter);
            advance(iter, 2);
        }
        else
            iter=vi.erase(iter);
    }

    for(auto i:vi)
        cout<<i<<" ";
    cout<<endl;
}
<commit_msg>Update ex9_31_1.cpp<commit_after>//
//  ex9_31.cpp
//  Exercise 9.31
//
//  Created by pezy on 12/3/14.
//  Copyright (c) 2014 pezy. All rights reserved.
//
//  @Brief  The program on page 354 to remove even-valued elements and
//          duplicate odd ones will not work on a list or forward_list. Why?
//          Revise the program so that it works on these types as well.
//  @list   ++iter; ++iter; -> advance(iter, 2);
//

#include <iostream>
#include <list>

using std::cout;
using std::endl;
using std::list;
using std::advance;

int main()
{
    list<int> vi={0,1,2,3,4,5,6,7,8,9};
    auto iter=vi.begin();
    while(iter!=vi.end())
    {
        if(*iter%2)
        {
            iter=vi.insert(iter, *iter);
            advance(iter, 2);
        }
        else
            iter=vi.erase(iter);
    }

    for(auto i:vi)
        cout<<i<<" ";
    cout<<endl;
}

{'fraction_non_alphanumeric': 0.16023054755043228, 'fraction_numerical': 0.03861671469740634, 'mean_word_length': 2.088967971530249, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5170288', 'n_tokens_mistral': 661, 'n_tokens_neox': 630, 'n_words': 173}