Skip to content

Commit 892e3f6

Browse files
committed
Modernize loops to use C++11 range-based-for
1 parent 2cc5467 commit 892e3f6

32 files changed

+162
-188
lines changed

src/sst/core/baseComponent.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,8 @@ BaseComponent::addWatchPointRecursive(WatchPoint* pt)
993993

994994

995995
// Call for my subcomponents
996-
for ( auto it = my_info_->subComponents.begin(); it != my_info_->subComponents.end(); ++it ) {
997-
it->second.component->addWatchPointRecursive(pt);
996+
for ( auto& subComponent : my_info_->subComponents ) {
997+
subComponent.second.component->addWatchPointRecursive(pt);
998998
}
999999
}
10001000

@@ -1036,8 +1036,8 @@ BaseComponent::removeWatchPointRecursive(WatchPoint* pt)
10361036
}
10371037

10381038
// Call for my subcomponents
1039-
for ( auto it = my_info_->subComponents.begin(); it != my_info_->subComponents.end(); ++it ) {
1040-
it->second.component->removeWatchPointRecursive(pt);
1039+
for ( auto& subComponent : my_info_->subComponents ) {
1040+
subComponent.second.component->removeWatchPointRecursive(pt);
10411041
}
10421042
}
10431043

src/sst/core/componentInfo.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ ComponentInfo::serialize_comp(SST::Core::Serialization::serializer& ser)
197197
{
198198
SST_SER(component);
199199
SST_SER(link_map);
200-
for ( auto it = subComponents.begin(); it != subComponents.end(); ++it ) {
201-
it->second.serialize_comp(ser);
200+
for ( auto& subComponent : subComponents ) {
201+
subComponent.second.serialize_comp(ser);
202202
}
203203
}
204204

src/sst/core/configBase.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,15 @@ ConfigBase::parseWallTimeToSeconds(const std::string& arg, bool& success, const
160160
}
161161

162162
static const char* templates[] = { "%H:%M:%S", "%M:%S", "%S", "%Hh", "%Mm", "%Ss" };
163-
const size_t n_templ = sizeof(templates) / sizeof(templates[0]);
164163
#pragma GCC diagnostic push
165164
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
166165
struct tm res = {}; /* This warns on GCC 4.8 due to a bug in GCC */
167166
#pragma GCC diagnostic pop
168167
char* p;
169168

170-
for ( size_t i = 0; i < n_templ; i++ ) {
169+
for ( auto& i : templates ) {
171170
memset(&res, '\0', sizeof(res));
172-
p = strptime(arg.c_str(), templates[i], &res);
171+
p = strptime(arg.c_str(), i, &res);
173172
if ( p != nullptr && *p == '\0' ) {
174173
seconds = res.tm_sec;
175174
seconds += res.tm_min * 60;
@@ -181,8 +180,8 @@ ConfigBase::parseWallTimeToSeconds(const std::string& arg, bool& success, const
181180
fprintf(stderr,
182181
"ERROR: for option \"%s\", wall time argument could not be parsed. Argument = [%s]\nValid formats are:\n",
183182
option.c_str(), arg.c_str());
184-
for ( size_t i = 0; i < n_templ; i++ ) {
185-
fprintf(stderr, "\t%s\n", templates[i]);
183+
for ( auto& i : templates ) {
184+
fprintf(stderr, "\t%s\n", i);
186185
}
187186
success = false;
188187
// Let caller handle error
@@ -301,8 +300,8 @@ ConfigBase::printUsage()
301300
if ( has_extended_help_ ) {
302301
fprintf(stderr, "\nOptions annotated with 'H' have extended help available\n");
303302
}
304-
for ( size_t i = 0; i < annotations_.size(); ++i ) {
305-
fprintf(stderr, "%s\n", annotations_[i].help.c_str());
303+
for ( auto& annotation : annotations_ ) {
304+
fprintf(stderr, "%s\n", annotation.help.c_str());
306305
}
307306

308307
// Print info about annotations

src/sst/core/configShared.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,13 @@ ConfigShared::getLibPath(bool exclude_ext_paths) const
102102
std::set<std::string> configGroups = envConfig->getGroupNames();
103103

104104
// iterate over groups of settings
105-
for ( auto groupItr = configGroups.begin(); groupItr != configGroups.end(); groupItr++ ) {
106-
SST::Core::Environment::EnvironmentConfigGroup* currentGroup = envConfig->getGroupByName(*groupItr);
105+
for ( const auto& configGroup : configGroups ) {
106+
SST::Core::Environment::EnvironmentConfigGroup* currentGroup = envConfig->getGroupByName(configGroup);
107107
std::set<std::string> groupKeys = currentGroup->getKeys();
108108

109109
// find which keys have a LIBDIR at the END of the key we
110110
// recognize these may house elements
111-
for ( auto keyItr = groupKeys.begin(); keyItr != groupKeys.end(); keyItr++ ) {
112-
const std::string& key = *keyItr;
111+
for ( const auto& key : groupKeys ) {
113112
const std::string& value = currentGroup->getValue(key);
114113

115114
if ( key.size() >= 6 ) {

src/sst/core/env/envconfig.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ SST::Core::Environment::EnvironmentConfigGroup::getKeys() const
3838
{
3939
std::set<std::string> retKeys;
4040

41-
for ( auto mapItr = params.begin(); mapItr != params.end(); mapItr++ ) {
42-
retKeys.insert(mapItr->first);
41+
for ( const auto& param : params ) {
42+
retKeys.insert(param.first);
4343
}
4444

4545
return retKeys;
@@ -80,8 +80,8 @@ SST::Core::Environment::EnvironmentConfigGroup::print()
8080

8181
printf("\n");
8282

83-
for ( auto paramsItr = params.begin(); paramsItr != params.end(); paramsItr++ ) {
84-
printf("%s=%s\n", paramsItr->first.c_str(), paramsItr->second.c_str());
83+
for ( auto& param : params ) {
84+
printf("%s=%s\n", param.first.c_str(), param.second.c_str());
8585
}
8686
}
8787

@@ -90,8 +90,8 @@ SST::Core::Environment::EnvironmentConfigGroup::writeTo(FILE* outFile)
9090
{
9191
fprintf(outFile, "\n[%s]\n", groupName.c_str());
9292

93-
for ( auto paramsItr = params.begin(); paramsItr != params.end(); paramsItr++ ) {
94-
fprintf(outFile, "%s=%s\n", paramsItr->first.c_str(), paramsItr->second.c_str());
93+
for ( auto& param : params ) {
94+
fprintf(outFile, "%s=%s\n", param.first.c_str(), param.second.c_str());
9595
}
9696
}
9797

@@ -100,8 +100,8 @@ SST::Core::Environment::EnvironmentConfiguration::EnvironmentConfiguration() {}
100100
SST::Core::Environment::EnvironmentConfiguration::~EnvironmentConfiguration()
101101
{
102102
// Delete all the groups we have created
103-
for ( auto groupItr = groups.begin(); groupItr != groups.end(); groupItr++ ) {
104-
delete groupItr->second;
103+
for ( auto& group : groups ) {
104+
delete group.second;
105105
}
106106
}
107107

@@ -136,8 +136,8 @@ SST::Core::Environment::EnvironmentConfiguration::getGroupNames()
136136
{
137137
std::set<std::string> groupNames;
138138

139-
for ( auto groupItr = groups.begin(); groupItr != groups.end(); groupItr++ ) {
140-
groupNames.insert(groupItr->first);
139+
for ( auto& group : groups ) {
140+
groupNames.insert(group.first);
141141
}
142142

143143
return groupNames;
@@ -152,8 +152,8 @@ SST::Core::Environment::EnvironmentConfiguration::getGroupByName(const std::stri
152152
void
153153
SST::Core::Environment::EnvironmentConfiguration::print()
154154
{
155-
for ( auto groupItr = groups.begin(); groupItr != groups.end(); groupItr++ ) {
156-
groupItr->second->print();
155+
for ( auto& group : groups ) {
156+
group.second->print();
157157
}
158158
}
159159

@@ -173,8 +173,8 @@ SST::Core::Environment::EnvironmentConfiguration::writeTo(const std::string& fil
173173
// exclusive since no one else should muck with it)
174174
flock(outputFD, LOCK_EX);
175175

176-
for ( auto groupItr = groups.begin(); groupItr != groups.end(); groupItr++ ) {
177-
groupItr->second->writeTo(output);
176+
for ( auto& group : groups ) {
177+
group.second->writeTo(output);
178178
}
179179

180180
flock(outputFD, LOCK_UN);
@@ -184,7 +184,7 @@ SST::Core::Environment::EnvironmentConfiguration::writeTo(const std::string& fil
184184
void
185185
SST::Core::Environment::EnvironmentConfiguration::writeTo(FILE* output)
186186
{
187-
for ( auto groupItr = groups.begin(); groupItr != groups.end(); groupItr++ ) {
188-
groupItr->second->writeTo(output);
187+
for ( auto& group : groups ) {
188+
group.second->writeTo(output);
189189
}
190190
}

src/sst/core/env/envquery.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ SST::Core::Environment::getSSTEnvironmentConfiguration(const std::vector<std::st
198198
}
199199

200200
// NEXT - override paths
201-
for ( std::string nextPath : overridePaths ) {
201+
for ( const std::string& nextPath : overridePaths ) {
202202
populateEnvironmentConfig(nextPath, envConfig, true);
203203
}
204204

src/sst/core/factory.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ Factory::getLoadedLibraryNames(std::set<std::string>& lib_names)
632632
void
633633
Factory::loadUnloadedLibraries(const std::set<std::string>& lib_names)
634634
{
635-
for ( std::set<std::string>::const_iterator i = lib_names.begin(); i != lib_names.end(); ++i ) {
636-
findLibrary(*i);
635+
for ( const auto& lib_name : lib_names ) {
636+
findLibrary(lib_name);
637637
}
638638
}
639639

src/sst/core/impl/partitioners/rrobin.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ SSTRoundRobinPartition::performPartition(PartitionGraph* graph)
2929
PartitionComponentMap_t& compMap = graph->getComponentMap();
3030
RankInfo rank(0, 0);
3131

32-
for ( PartitionComponentMap_t::iterator compItr = compMap.begin(); compItr != compMap.end(); compItr++ ) {
32+
for ( auto& compItr : compMap ) {
3333

34-
(*compItr)->rank = rank;
34+
compItr->rank = rank;
3535

3636
rank.rank++;
3737
if ( rank.rank == world_size.rank ) {

src/sst/core/impl/partitioners/simplepart.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ cost_external_links(ComponentId_t* setA, const int lengthA, ComponentId_t* setB,
7474

7575
for ( int i = 0; i < lengthA; i++ ) {
7676
auto* compMap = timeTable[setA[i]];
77-
for ( auto compMapItr = compMap->cbegin(); compMapItr != compMap->cend(); compMapItr++ ) {
78-
if ( findIndex(setB, lengthB, compMapItr->first) > -1 ) {
79-
cost += compMapItr->second;
77+
for ( auto compMapItr : *compMap ) {
78+
if ( findIndex(setB, lengthB, compMapItr.first) > -1 ) {
79+
cost += compMapItr.second;
8080
}
8181
}
8282
}
@@ -186,10 +186,9 @@ SimplePartitioner::performPartition(PartitionGraph* graph)
186186
PartitionComponentMap_t& component_map = graph->getComponentMap();
187187

188188
if ( total_parts == 1 ) {
189-
for ( PartitionComponentMap_t::iterator compItr = component_map.begin(); compItr != component_map.end();
190-
++compItr ) {
189+
for ( auto& compItr : component_map ) {
191190

192-
(*compItr)->rank = RankInfo(0, 0);
191+
compItr->rank = RankInfo(0, 0);
193192
}
194193
}
195194
else {
@@ -211,10 +210,9 @@ SimplePartitioner::performPartition(PartitionGraph* graph)
211210

212211
// size_t nComp = component_map.size();
213212
// for(size_t theComponent = 0 ; theComponent < nComp ; theComponent++ ) {
214-
for ( PartitionComponentMap_t::iterator compItr = component_map.begin(); compItr != component_map.end();
215-
++compItr ) {
213+
for ( auto& compItr : component_map ) {
216214

217-
ComponentId_t theComponent = (*compItr)->id;
215+
ComponentId_t theComponent = compItr->id;
218216

219217
auto compConnectMap = timeTable[theComponent] = new std::map<ComponentId_t, SimTime_t>();
220218

@@ -225,15 +223,14 @@ SimplePartitioner::performPartition(PartitionGraph* graph)
225223
setB[indexB++] = theComponent;
226224
}
227225

228-
LinkIdMap_t component_links = (*compItr)->links;
226+
LinkIdMap_t component_links = compItr->links;
229227

230228
PartitionLinkMap_t& linkMap = graph->getLinkMap();
231229

232-
for ( LinkIdMap_t::const_iterator linkItr = component_links.begin(); linkItr != component_links.end();
233-
linkItr++ ) {
230+
for ( unsigned int component_link : component_links ) {
234231

235232
// ConfigLink* theLink = (*linkItr);
236-
PartitionLink& theLink = linkMap[*linkItr];
233+
PartitionLink& theLink = linkMap[component_link];
237234
compConnectMap->insert(
238235
std::pair<ComponentId_t, SimTime_t>(theLink.component[1], theLink.getMinLatency()));
239236
}

src/sst/core/impl/timevortex/timeVortexPQ.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ TimeVortexPQBase<TS>::dbg_print(Output& out) const
102102

103103
// STL's priority_queue does not support iteration.
104104
const std::vector<Activity*>& act = getContainer();
105-
for ( auto it = act.begin(); it != act.end(); it++ ) {
106-
(*it)->print(" ", out);
105+
for ( auto it : act ) {
106+
it->print(" ", out);
107107
}
108108
}
109109

0 commit comments

Comments
 (0)