Skip to content

Commit ca11be2

Browse files
committed
coding style: use C++11 for-each construct
... instead of BOOST_FOREACH(...) Closes: https://github.com/kdudka/csdiff/pull/15
1 parent 21ee38c commit ca11be2

15 files changed

+33
-50
lines changed

src/abstract-filter.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <vector>
2828

2929
#include <boost/algorithm/string/replace.hpp>
30-
#include <boost/foreach.hpp>
3130

3231
// /////////////////////////////////////////////////////////////////////////////
3332
// implementation of PredicateFilter
@@ -51,7 +50,7 @@ PredicateFilter::PredicateFilter(AbstractWriter *slave):
5150

5251
PredicateFilter::~PredicateFilter()
5352
{
54-
BOOST_FOREACH(IPredicate *pred, d->preds_)
53+
for (IPredicate *pred : d->preds_)
5554
delete pred;
5655

5756
delete d;
@@ -71,7 +70,7 @@ bool PredicateFilter::matchDef(const Defect &def)
7170
{
7271
const bool neg = d->invertEach_;
7372

74-
BOOST_FOREACH(const IPredicate *pred, d->preds_) {
73+
for (const IPredicate *pred : d->preds_) {
7574
if (neg == pred->matchDef(def))
7675
return false;
7776
}
@@ -110,7 +109,7 @@ void dropCtxLines(TEvtList *pEvtList)
110109
static CtxEventDetector detector;
111110

112111
TEvtList dst;
113-
BOOST_FOREACH(const DefEvent &evt, *pEvtList) {
112+
for (const DefEvent &evt : *pEvtList) {
114113
if (detector.isAnyCtxLine(evt))
115114
continue;
116115

src/abstract-parser.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include "gcc-parser.hh"
2424
#include "json-parser.hh"
2525

26-
#include <boost/foreach.hpp>
27-
2826
AbstractParser* createParser(
2927
std::istream &input,
3028
const std::string &fileName,

src/csdiff-core.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
#include "deflookup.hh"
2424
#include "json-writer.hh"
2525

26-
#include <boost/foreach.hpp>
2726
#include <boost/shared_ptr.hpp>
2827

2928
// FIXME: some keys should be merge more intelligently if they already exist
3029
// TODO: define a nesting limit for keys like diffbase-diffbase-diffbase-...
3130
void mergeScanProps(TScanProps &props, const TScanProps &oldProps)
3231
{
33-
BOOST_FOREACH(TScanProps::const_reference item, oldProps) {
32+
for (TScanProps::const_reference item : oldProps) {
3433
const std::string &oldKey = item.first;
3534
const std::string &oldVal = item.second;
3635
std::string key("diffbase-");

src/csdiff.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include <cstdlib>
2626

27-
#include <boost/foreach.hpp>
2827
#include <boost/program_options.hpp>
2928
#include <boost/regex.hpp>
3029

@@ -121,7 +120,7 @@ int main(int argc, char *argv[])
121120
const TStringList &substList = vm["file-rename"].as<TStringList>();
122121
boost::smatch sm;
123122
const boost::regex reSubst("([^,]+),(.*)");
124-
BOOST_FOREACH(const string &subst, substList) {
123+
for (const string &subst : substList) {
125124
if (!boost::regex_match(subst, sm, reSubst)) {
126125
std::cerr << "bad substutution format: " << subst
127126
<< std::endl << "use: -s OLD,NEW" << std::endl;

src/csfilter.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <iostream>
2323

2424
#include <boost/regex.hpp>
25-
#include <boost/foreach.hpp>
2625

2726
// Setup verbosity for debugging string substitions while matching them.
2827
// Verbosity levels are from 0 to 3 (0 is off)
@@ -118,7 +117,7 @@ struct MsgFilter::Private {
118117
"PROSPECTOR_WARNING",
119118
"PYLINT_WARNING"
120119
};
121-
BOOST_FOREACH(const std::string &checker, pylintCheckers) {
120+
for (const std::string &checker : pylintCheckers) {
122121
// "Too many lines in module (1152/1000)" etc.
123122
addMsgFilter(checker, " \\([0-9]+/[0-9]+\\)$", "");
124123

@@ -144,8 +143,8 @@ MsgFilter::MsgFilter():
144143

145144
MsgFilter::~MsgFilter()
146145
{
147-
BOOST_FOREACH(TMsgFilterMap::const_reference item, d->msgFilterMap)
148-
BOOST_FOREACH(struct MsgReplace *rpl, item.second)
146+
for (TMsgFilterMap::const_reference item : d->msgFilterMap)
147+
for (struct MsgReplace *rpl : item.second)
149148
delete rpl;
150149

151150
delete d;
@@ -168,12 +167,12 @@ std::string MsgFilter::filterMsg(
168167
const std::string &checker)
169168
{
170169
std::string filtered = msg;
171-
BOOST_FOREACH(const struct MsgReplace *rpl, d->msgFilterMap[checker]) {
170+
for (const struct MsgReplace *rpl : d->msgFilterMap[checker]) {
172171
filtered = regexReplaceWrap(filtered, rpl->regex, rpl->replaceWith);
173172
}
174173

175174
// these substitutions are common for all checkers
176-
BOOST_FOREACH(const struct MsgReplace *rpl, d->msgFilterMap[""]) {
175+
for (const struct MsgReplace *rpl : d->msgFilterMap[""]) {
177176
filtered = regexReplaceWrap(filtered, rpl->regex, rpl->replaceWith);
178177
}
179178

src/csgrep.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <iomanip>
2929
#include <map>
3030

31-
#include <boost/foreach.hpp>
3231
#include <boost/program_options.hpp>
3332
#include <boost/regex.hpp>
3433

@@ -95,7 +94,7 @@ class DefCounter: public StatWriter {
9594
}
9695

9796
virtual void flush() {
98-
BOOST_FOREACH(TMap::const_reference item, cnt_) {
97+
for (TMap::const_reference item : cnt_) {
9998
using namespace std;
10099
const ios_base::fmtflags oldFlags = cout.flags();
101100
const int oldWidth = cout.width();
@@ -121,7 +120,7 @@ class EvtCounter: public StatWriter {
121120
}
122121

123122
virtual void flush() {
124-
BOOST_FOREACH(TMap::const_reference item, cnt_) {
123+
for (TMap::const_reference item : cnt_) {
125124
using namespace std;
126125
const ios_base::fmtflags oldFlags = cout.flags();
127126
const int oldWidth = cout.width();
@@ -144,7 +143,7 @@ class FileDefCounter: public StatWriter {
144143

145144
public:
146145
virtual ~FileDefCounter() {
147-
BOOST_FOREACH(TMap::const_reference item, cntMap_)
146+
for (TMap::const_reference item : cntMap_)
148147
delete /* (DefCounter *) */ item.second;
149148
}
150149

@@ -160,7 +159,7 @@ class FileDefCounter: public StatWriter {
160159
}
161160

162161
virtual void flush() {
163-
BOOST_FOREACH(TMap::const_reference item, cntMap_) {
162+
for (TMap::const_reference item : cntMap_) {
164163
const std::string fName = item.first;
165164
std::cout << "\n\n--- " << fName << " ---\n";
166165

@@ -181,7 +180,7 @@ class MsgPredicate: public IPredicate {
181180
}
182181

183182
virtual bool matchDef(const Defect &def) const {
184-
BOOST_FOREACH(const DefEvent &evt, def.events) {
183+
for (const DefEvent &evt : def.events) {
185184
if (boost::regex_search(evt.msg, re_))
186185
return true;
187186
}
@@ -323,7 +322,7 @@ class PathStripper: public GenericAbstractFilter {
323322
Defect def(defOrig);
324323

325324
// iterate through all events
326-
BOOST_FOREACH(DefEvent &evt, def.events) {
325+
for (DefEvent &evt : def.events) {
327326
std::string &path = evt.fileName;
328327
if (path.size() < prefSize_)
329328
continue;
@@ -638,7 +637,7 @@ int main(int argc, char *argv[])
638637
}
639638
else {
640639
const TStringList &files = vm["input-file"].as<TStringList>();
641-
BOOST_FOREACH(const string &fileName, files) {
640+
for (const string &fileName : files) {
642641
if (!eng->handleFile(fileName, silent))
643642
hasError = true;
644643
}

src/cslinker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bool loadPropsFromIniFile(
6767

6868
// update scan properties from the ptree node
6969
pt::ptree scanNode = root.get_child("scan");
70-
BOOST_FOREACH(const pt::ptree::value_type &item, scanNode)
70+
for (const pt::ptree::value_type &item : scanNode)
7171
props[item.first] = item.second.data();
7272

7373
// write the updated scan properties back to the writer

src/cssort.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "abstract-writer.hh"
2121
#include "version.hh"
2222

23-
#include <boost/foreach.hpp>
2423
#include <boost/program_options.hpp>
2524
#include <boost/regex.hpp>
2625

@@ -53,7 +52,7 @@ class GenericSort: public AbstractWriter {
5352
createWriter(std::cout, this->inputFormat(), cm_, scanProps_);
5453

5554
// write the data
56-
BOOST_FOREACH(const Defect &def, cont_)
55+
for (const Defect &def : cont_)
5756
writer->handleDef(def);
5857

5958
// flush data and destroy writer
@@ -238,7 +237,7 @@ int main(int argc, char *argv[])
238237
}
239238
else {
240239
const TStringList &files = vm["input-file"].as<TStringList>();
241-
BOOST_FOREACH(const string &fileName, files) {
240+
for (const string &fileName : files) {
242241
if (!eng->handleFile(fileName, silent))
243242
hasError = true;
244243
}

src/cstrans-df-run.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include <boost/algorithm/string/replace.hpp>
2323
#include <boost/filesystem.hpp>
24-
#include <boost/foreach.hpp>
2524
#include <boost/program_options.hpp>
2625
#include <boost/regex.hpp>
2726
#include <boost/tokenizer.hpp>
@@ -75,7 +74,7 @@ void appendExecArgs(TStringList *pExecList, const std::string &str)
7574
std::string arg;
7675

7776
// process the given string char by char
78-
BOOST_FOREACH(const unsigned char c, str) {
77+
for (const unsigned char c : str) {
7978
switch (state) {
8079
case ES_SEEK_QUOT_OPEN:
8180
if ('\"' == c)
@@ -150,7 +149,7 @@ std::string runLineFromExecList(const TStringList &execList)
150149
// construct RUN ["cmd", "arg1", "arg2", ...] from execList
151150
std::string runLine = "RUN [";
152151
int i = 0;
153-
BOOST_FOREACH (const std::string &arg, execList) {
152+
for (const std::string &arg : execList) {
154153
if (i++)
155154
runLine += ", ";
156155

src/cswriter.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
#include "cswriter.hh"
2121

22-
#include <boost/foreach.hpp>
23-
2422
struct CovWriter::Private {
2523
std::ostream &str;
2624
ColorWriter cw;
@@ -62,7 +60,7 @@ void CovWriter::handleDef(const Defect &def)
6260
str << def.annotation;
6361
str << d->cw.setColor(C_NO_COLOR) << ":\n";
6462

65-
BOOST_FOREACH(const DefEvent &evt, def.events) {
63+
for (const DefEvent &evt : def.events) {
6664
const bool isKeyEvt = !evt.verbosityLevel;
6765
if (!isKeyEvt)
6866
str << d->cw.setColor(C_DARK_GRAY);

0 commit comments

Comments
 (0)