]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/error.cc
give a descriptive error for pipe tries with 'false'
[apt.git] / apt-pkg / contrib / error.cc
index 892cd48742de54ced9117a26521607a5b8c38f26..8a87e16e9e1fbdb404bfb289f936152fbaad2f07 100644 (file)
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include <string>
 #include <cstring>
+#include <algorithm>
 
                                                                        /*}}}*/
 
@@ -212,12 +213,13 @@ void GlobalError::DumpErrors(std::ostream &out, MsgType const &threshold,
        if (mergeStack == true)
                for (std::list<MsgStack>::const_reverse_iterator s = Stacks.rbegin();
                     s != Stacks.rend(); ++s)
-                       Messages.insert(Messages.begin(), s->Messages.begin(), s->Messages.end());
+                       std::copy(s->Messages.begin(), s->Messages.end(), std::front_inserter(Messages));
+
+       std::for_each(Messages.begin(), Messages.end(), [&threshold, &out](Item const &m) {
+               if (m.Type >= threshold)
+                       out << m << std::endl;
+       });
 
-       for (std::list<Item>::const_iterator m = Messages.begin();
-            m != Messages.end(); ++m)
-               if (m->Type >= threshold)
-                       out << (*m) << std::endl;
        Discard();
 }
                                                                        /*}}}*/
@@ -228,25 +230,21 @@ void GlobalError::Discard() {
 }
                                                                        /*}}}*/
 // GlobalError::empty - does our error list include anything?          /*{{{*/
-bool GlobalError::empty(MsgType const &trashhold) const {
+bool GlobalError::empty(MsgType const &threshold) const {
        if (PendingFlag == true)
                return false;
 
        if (Messages.empty() == true)
                return true;
 
-       for (std::list<Item>::const_iterator m = Messages.begin();
-            m != Messages.end(); ++m)
-               if (m->Type >= trashhold)
-                       return false;
-
-       return true;
+       return std::find_if(Messages.begin(), Messages.end(), [&threshold](Item const &m) {
+               return m.Type >= threshold;
+       }) == Messages.end();
 }
                                                                        /*}}}*/
 // GlobalError::PushToStack                                            /*{{{*/
 void GlobalError::PushToStack() {
-       MsgStack pack(Messages, PendingFlag);
-       Stacks.push_back(pack);
+       Stacks.emplace_back(Messages, PendingFlag);
        Discard();
 }
                                                                        /*}}}*/
@@ -262,7 +260,7 @@ void GlobalError::RevertToStack() {
 // GlobalError::MergeWithStack                                         /*{{{*/
 void GlobalError::MergeWithStack() {
        MsgStack pack = Stacks.back();
-       Messages.insert(Messages.begin(), pack.Messages.begin(), pack.Messages.end());
+       Messages.splice(Messages.begin(), pack.Messages);
        PendingFlag = PendingFlag || pack.PendingFlag;
        Stacks.pop_back();
 }