[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master d0ed943 2/2: Modernize for statements
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master d0ed943 2/2: Modernize for statements |
Date: |
Sun, 15 Jan 2017 17:43:11 +0000 (UTC) |
branch: master
commit d0ed9439f3a9f917304ccc24a2bd624c8620845e
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Modernize for statements
---
census_view.cpp | 72 +++++++++++++++++++++-------------------------
crc32.cpp | 4 +--
dbdict.cpp | 15 ++++------
input_sequence.cpp | 16 +++--------
input_sequence_entry.cpp | 34 +++++++++++-----------
wx_table_generator.cpp | 18 ++++++------
6 files changed, 68 insertions(+), 91 deletions(-)
diff --git a/census_view.cpp b/census_view.cpp
index a7741de..fc59bb9 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -69,14 +69,13 @@ std::string insert_spaces_between_words(std::string const&
s)
{
std::string r;
std::insert_iterator<std::string> j(r, r.begin());
- std::string::const_iterator i;
- for(i = s.begin(); i != s.end(); ++i)
+ for(auto const& i : s)
{
- if(is_ok_for_cctype(*i) && std::isupper(*i) && !r.empty())
+ if(is_ok_for_cctype(i) && std::isupper(i) && !r.empty())
{
*j++ = ' ';
}
- *j++ = *i;
+ *j++ = i;
}
return r;
}
@@ -966,10 +965,9 @@ bool CensusView::column_value_varies_across_cells
,std::vector<Input> const& cells
) const
{
- typedef std::vector<Input>::const_iterator ici;
- for(ici j = cells.begin(); j != cells.end(); ++j)
+ for(auto const& j : cells)
{
- if(!((*j)[header] == case_parms()[0][header]))
+ if(!(j[header] == case_parms()[0][header]))
{
return true;
}
@@ -1036,10 +1034,9 @@ void CensusView::update_class_names()
// Extract names and add them even if they might be duplicates.
std::vector<std::string> all_class_names;
- typedef std::vector<Input>::const_iterator ici;
- for(ici i = cell_parms().begin(); i != cell_parms().end(); ++i)
+ for(auto const& i : cell_parms())
{
- all_class_names.push_back((*i)["EmployeeClass"].str());
+ all_class_names.push_back(i["EmployeeClass"].str());
}
std::vector<std::string> unique_class_names;
@@ -1123,36 +1120,33 @@ void CensusView::apply_changes
std::vector<std::string> headers_of_changed_parameters;
std::vector<std::string> const&
all_headers(case_parms()[0].member_names());
- typedef std::vector<std::string>::const_iterator sci;
- for(sci i = all_headers.begin(); i != all_headers.end(); ++i)
+ for(auto const& i : all_headers)
{
- if(!(old_parms[*i] == new_parms[*i]))
+ if(!(old_parms[i] == new_parms[i]))
{
- headers_of_changed_parameters.push_back(*i);
+ headers_of_changed_parameters.push_back(i);
}
}
- for(sci i = headers_of_changed_parameters.begin(); i !=
headers_of_changed_parameters.end(); ++i)
+ for(auto const& i : headers_of_changed_parameters)
{
if(!for_this_class_only)
{
- typedef std::vector<Input>::iterator ii;
- for(ii j = class_parms().begin(); j != class_parms().end(); ++j)
+ for(auto& j : class_parms())
{
- (*j)[*i] = new_parms[*i].str();
+ j[i] = new_parms[i].str();
}
- for(ii j = cell_parms ().begin(); j != cell_parms ().end(); ++j)
+ for(auto& j : cell_parms())
{
- (*j)[*i] = new_parms[*i].str();
+ j[i] = new_parms[i].str();
}
}
else
{
- typedef std::vector<Input>::iterator ii;
- for(ii j = cell_parms().begin(); j != cell_parms().end(); ++j)
+ for(auto& j : cell_parms())
{
- if((*j)["EmployeeClass"] == old_parms["EmployeeClass"])
+ if(j["EmployeeClass"] == old_parms["EmployeeClass"])
{
- (*j)[*i] = new_parms[*i].str();
+ j[i] = new_parms[i].str();
}
}
}
@@ -1161,14 +1155,13 @@ void CensusView::apply_changes
// Probably this should be factored out into a member function
// that's called elsewhere too--e.g., when a cell is read from
// file, or when a census is pasted.
- typedef std::vector<Input>::iterator ii;
- for(ii j = class_parms().begin(); j != class_parms().end(); ++j)
+ for(auto& j : class_parms())
{
- j->Reconcile();
+ j.Reconcile();
}
- for(ii j = cell_parms() .begin(); j != cell_parms() .end(); ++j)
+ for(auto& j : cell_parms())
{
- j->Reconcile();
+ j.Reconcile();
}
}
@@ -1197,25 +1190,25 @@ void CensusView::update_visible_columns()
// still information--so if the user made them different from any cell
// wrt some column, we respect that conscious decision.
std::vector<std::string> const&
all_headers(case_parms()[0].member_names());
- std::vector<std::string>::const_iterator i;
- unsigned int column;
- for(i = all_headers.begin(), column = 0; i != all_headers.end(); ++i,
++column)
+ unsigned int column = 0;
+ for(auto const& i : all_headers)
{
+ ++column;
if
- ( column_value_varies_across_cells(*i, class_parms())
- || column_value_varies_across_cells(*i, cell_parms ())
+ ( column_value_varies_across_cells(i, class_parms())
+ || column_value_varies_across_cells(i, cell_parms ())
)
{
- any_member<Input> const& representative_value =
list_model_->cell_at(0, 1 + column);
+ any_member<Input> const& representative_value =
list_model_->cell_at(0, column);
wxDataViewRenderer* renderer =
renderer_type_converter::get(representative_value).create_renderer(representative_value);
LMI_ASSERT(renderer);
list_window_->AppendColumn
(new(wx) wxDataViewColumn
- (insert_spaces_between_words(*i)
+ (insert_spaces_between_words(i)
,renderer
- ,1 + column
+ ,column
,width
,wxALIGN_LEFT
,wxDATAVIEW_COL_RESIZABLE
@@ -1509,10 +1502,9 @@ void CensusView::UponDeleteCells(wxCommandEvent&)
Timer timer;
wxArrayInt erasures;
- typedef wxDataViewItemArray::const_iterator dvci;
- for(dvci i = selection.begin(); i != selection.end(); ++i)
+ for(auto const& i : selection)
{
- erasures.push_back(list_model_->GetRow(*i));
+ erasures.push_back(list_model_->GetRow(i));
}
std::sort(erasures.begin(), erasures.end());
diff --git a/crc32.cpp b/crc32.cpp
index 89a6b45..3f1558b 100644
--- a/crc32.cpp
+++ b/crc32.cpp
@@ -151,9 +151,9 @@ unsigned int CRC::value() const
//============================================================================
CRC& CRC::operator+=(std::string const& z)
{
- for(unsigned int j = 0; j < z.length(); j++)
+ for(auto const& j : z)
{
- operator+=(z[j]);
+ operator+=(j);
}
return *this;
}
diff --git a/dbdict.cpp b/dbdict.cpp
index c278897..dfe75f5 100644
--- a/dbdict.cpp
+++ b/dbdict.cpp
@@ -511,10 +511,9 @@ void DBDictionary::InitDB()
static double const dbl_inf = infinity<double>();
static double const bignum = std::numeric_limits<double>::max();
- typedef std::vector<std::string>::const_iterator svci;
- for(svci i = member_names().begin(); i != member_names().end(); ++i)
+ for(auto const& i : member_names())
{
- Add(database_entity(db_key_from_name(*i), 0.0));
+ Add(database_entity(db_key_from_name(i), 0.0));
}
// It would be dangerous to set these to zero.
@@ -966,10 +965,9 @@ void DBDictionary::InitAntediluvian()
// Zero is inappropriate for some entities ("DB_CurrCoiMultiplier",
// e.g.), but the antediluvian branch doesn't actually use most
// database entities.
- typedef std::vector<std::string>::const_iterator svci;
- for(svci i = member_names().begin(); i != member_names().end(); ++i)
+ for(auto const& i : member_names())
{
- Add(database_entity(db_key_from_name(*i), 0.0));
+ Add(database_entity(db_key_from_name(i), 0.0));
}
// These are the same as class date_trammel's nominal limits.
@@ -1085,10 +1083,9 @@ void print_databases()
fs::path out_file = fs::change_extension(*i, ".dbt");
fs::ofstream os(out_file, ios_out_trunc_binary());
- typedef std::vector<std::string>::const_iterator svci;
- for(svci i = z.member_names().begin(); i !=
z.member_names().end(); ++i)
+ for(auto const& i : z.member_names())
{
- z.datum(*i).write(os);
+ z.datum(i).write(os);
}
}
catch(...)
diff --git a/input_sequence.cpp b/input_sequence.cpp
index 5b69bfb..f57b814 100644
--- a/input_sequence.cpp
+++ b/input_sequence.cpp
@@ -133,13 +133,9 @@ InputSequence::InputSequence(std::vector<double> const& v)
intervals.push_back(dummy);
intervals.back().value_number = current_value;
- for
- (std::vector<double>::const_iterator vi = v.begin()
- ;vi != v.end()
- ;++vi
- )
+ for(auto const& vi : v)
{
- current_value = *vi;
+ current_value = vi;
if(prior_value == current_value)
{
++intervals.back().end_duration;
@@ -173,13 +169,9 @@ InputSequence::InputSequence(std::vector<std::string>
const& v)
intervals.push_back(dummy);
intervals.back().value_keyword = current_value;
- for
- (std::vector<std::string>::const_iterator vi = v.begin()
- ;vi != v.end()
- ;++vi
- )
+ for(auto const& vi : v)
{
- current_value = *vi;
+ current_value = vi;
if(prior_value == current_value)
{
++intervals.back().end_duration;
diff --git a/input_sequence_entry.cpp b/input_sequence_entry.cpp
index bd0e784..645fa31 100644
--- a/input_sequence_entry.cpp
+++ b/input_sequence_entry.cpp
@@ -75,7 +75,7 @@ struct choice_value
char const* label;
};
-choice_value duration_mode_choice_values[] =
+choice_value const duration_mode_choice_values[] =
{
{e_retirement, "until retirement"},
{e_attained_age, "until age"},
@@ -92,9 +92,9 @@ DurationModeChoice::DurationModeChoice(wxWindow* parent)
{
wxWindowUpdateLocker lock(this);
- for(unsigned int i = 0; i < duration_mode_choices; ++i)
+ for(auto const& i : duration_mode_choice_values)
{
- Append(duration_mode_choice_values[i].label);
+ Append(i.label);
}
}
@@ -137,11 +137,11 @@ void DurationModeChoice::allow_maturity(bool allow)
void DurationModeChoice::value(duration_mode x)
{
- for(unsigned int i = 0; i < duration_mode_choices; ++i)
+ for(auto const& i : duration_mode_choice_values)
{
- if(x == duration_mode_choice_values[i].mode)
+ if(x == i.mode)
{
- SetSelection(i);
+ SetStringSelection(i.label);
return;
}
}
@@ -694,11 +694,11 @@ void InputSequenceEditor::insert_row(int new_row)
sizer_->wxSizer::Insert(insert_pos++, add,
wxSizerFlags(flags).Border(wxLEFT, 0).Right());
// update id_to_row_ mapping:
- for(id_to_row_map::iterator i = id_to_row_.begin(); i != id_to_row_.end();
++i)
+ for(auto& i : id_to_row_)
{
- if(new_row <= i->second)
+ if(new_row <= i.second)
{
- i->second = i->second + 1;
+ i.second = i.second + 1;
}
}
@@ -808,23 +808,21 @@ void InputSequenceEditor::remove_row(int row)
// update id_to_row_ mapping:
std::vector<wxWindowID> to_remove;
- for(id_to_row_map::iterator i = id_to_row_.begin(); i != id_to_row_.end();
++i)
+ for(auto& i : id_to_row_)
{
- if(i->second == row)
+ if(i.second == row)
{
- to_remove.push_back(i->first);
+ to_remove.push_back(i.first);
}
- else if(row < i->second)
+ else if(row < i.second)
{
- i->second = i->second - 1;
+ i.second = i.second - 1;
}
}
LMI_ASSERT(!to_remove.empty());
- for(std::vector<wxWindowID>::const_iterator rm = to_remove.begin()
- ;rm != to_remove.end()
- ;++rm)
+ for(auto const& rm : to_remove)
{
- id_to_row_.erase(*rm);
+ id_to_row_.erase(rm);
}
// update the row following the one we just removed and the one before it,
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index b8a31da..100dc47 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -160,21 +160,20 @@ void
wx_table_generator::do_compute_column_widths_if_necessary()
int num_expand = 0;
int total_fixed = 0;
- typedef std::vector<column_info>::const_iterator cici;
- for(cici i = columns_.begin(); i != columns_.end(); ++i)
+ for(auto const& i : columns_)
{
- if(i->is_hidden())
+ if(i.is_hidden())
{
continue;
}
- if(0 == i->width_)
+ if(0 == i.width_)
{
num_expand++;
}
else
{
- total_fixed += i->width_;
+ total_fixed += i.width_;
}
}
@@ -189,17 +188,16 @@ void
wx_table_generator::do_compute_column_widths_if_necessary()
int const per_expand
= (total_width_ - total_fixed + num_expand - 1)/num_expand;
- typedef std::vector<column_info>::iterator cii;
- for(cii i = columns_.begin(); i != columns_.end(); ++i)
+ for(auto& i : columns_)
{
- if(i->is_hidden())
+ if(i.is_hidden())
{
continue;
}
- if(0 == i->width_)
+ if(0 == i.width_)
{
- i->width_ = per_expand;
+ i.width_ = per_expand;
}
}
}