From 93a471a336fd5d296e8750066dade2c7cc564e7c Mon Sep 17 00:00:00 2001 From: Charles-Henri Bruyand Date: Fri, 30 Mar 2018 14:44:50 +0200 Subject: [PATCH] rec: use C++11 range-based for loop --- pdns/arguments.cc | 38 +++++++++++++++++--------------------- pdns/resolver.cc | 21 +++++++++++---------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/pdns/arguments.cc b/pdns/arguments.cc index 2696ac3c8..1f2d04456 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -97,11 +97,10 @@ bool ArgvMap::contains(const string &var, const string &val) return false; } vector parts; - vector::const_iterator i; stringtok( parts, param->second, ", \t" ); - for( i = parts.begin(); i != parts.end(); ++i ) { - if( *i == val ) { + for (const auto& part: parts) { + if (part == val) { return true; } } @@ -115,30 +114,27 @@ string ArgvMap::helpstring(string prefix) prefix=""; string help; - - for(map::const_iterator i=helpmap.begin(); - i!=helpmap.end(); - ++i) - { - if(!prefix.empty() && i->first.find(prefix) != 0) // only print items with prefix - continue; + + for (const auto& i: helpmap) { + if(!prefix.empty() && i.first.find(prefix) != 0) // only print items with prefix + continue; help+=" --"; - help+=i->first; + help+=i.first; - string type=d_typeMap[i->first]; + string type=d_typeMap[i.first]; if(type=="Parameter") help+="=..."; else if(type=="Switch") { - help+=" | --"+i->first+"=yes"; - help+=" | --"+i->first+"=no"; + help+=" | --"+i.first+"=yes"; + help+=" | --"+i.first+"=no"; } help+="\n\t"; - help+=i->second; + help+=i.second; help+="\n"; } @@ -154,20 +150,20 @@ string ArgvMap::configstring(bool current) else help="# Autogenerated configuration file template\n"; - for(map::const_iterator i=helpmap.begin(); i!=helpmap.end(); ++i) { - if(d_typeMap[i->first]=="Command") + for(const auto& i: helpmap) { + if(d_typeMap[i.first]=="Command") continue; help+="#################################\n"; help+="# "; - help+=i->first; + help+=i.first; help+="\t"; - help+=i->second; + help+=i.second; help+="\n#\n"; if (current) { - help+=i->first+"="+params[i->first]+"\n\n"; + help+=i.first+"="+params[i.first]+"\n\n"; } else { - help+="# "+i->first+"="+params[i->first]+"\n\n"; + help+="# "+i.first+"="+params[i.first]+"\n\n"; } } return help; diff --git a/pdns/resolver.cc b/pdns/resolver.cc index 82b1df678..24e9cc979 100644 --- a/pdns/resolver.cc +++ b/pdns/resolver.cc @@ -115,9 +115,9 @@ Resolver::Resolver() Resolver::~Resolver() { - for(std::map::iterator iter = locals.begin(); iter != locals.end(); ++iter) { - if (iter->second >= 0) - close(iter->second); + for (auto& iter: locals) { + if (iter.second >= 0) + close(iter.second); } } @@ -205,11 +205,11 @@ static int parseResult(MOADNSParser& mdp, const DNSName& origQname, uint16_t ori vector ret; DNSResourceRecord rr; - for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) { - rr.qname = i->first.d_name; - rr.qtype = i->first.d_type; - rr.ttl = i->first.d_ttl; - rr.content = i->first.d_content->getZoneRepresentation(true); + for (const auto& i: mdp.d_answers) { + rr.qname = i.first.d_name; + rr.qtype = i.first.d_type; + rr.ttl = i.first.d_ttl; + rr.content = i.first.d_content->getZoneRepresentation(true); result->push_back(rr); } @@ -222,9 +222,10 @@ bool Resolver::tryGetSOASerial(DNSName *domain, ComboAddress* remote, uint32_t * size_t i = 0, k; int sock; - for(std::map::iterator iter=locals.begin(); iter != locals.end(); ++iter, ++i) { - fds[i].fd = iter->second; + for (const auto& iter: locals) { + fds[i].fd = iter.second; fds[i].events = POLLIN; + ++i; } if (poll(fds.get(), i, 250) < 1) { // wait for 0.25s -- 2.40.0