]> granicus.if.org Git - pdns/commitdiff
rec: use C++11 range-based for loop
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Fri, 30 Mar 2018 12:44:50 +0000 (14:44 +0200)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Fri, 30 Mar 2018 13:04:15 +0000 (15:04 +0200)
pdns/arguments.cc
pdns/resolver.cc

index 2696ac3c8dea87b98ec6bdd6cfaa5d816ad1a278..1f2d04456a0c2609a38c26fdd84887594bcb88b8 100644 (file)
@@ -97,11 +97,10 @@ bool ArgvMap::contains(const string &var, const string &val)
     return false;
   }
   vector<string> parts;
-  vector<string>::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<string,string>::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<string,string>::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;
index 82b1df6785711013f616a1de6e28c05d049e37a6..24e9cc97924c9a08a89bec760b1aac66a8873356 100644 (file)
@@ -115,9 +115,9 @@ Resolver::Resolver()
 
 Resolver::~Resolver()
 {
-  for(std::map<std::string,int>::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<DNSResourceRecord> 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<string,int>::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