]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
c++/subr.hh (subr::stackish): New template type.
authorRoland McGrath <roland@redhat.com>
Fri, 2 Oct 2009 21:26:42 +0000 (14:26 -0700)
committerRoland McGrath <roland@redhat.com>
Fri, 2 Oct 2009 21:26:42 +0000 (14:26 -0700)
libdw/ChangeLog
libdw/c++/subr.hh

index 019427d35557ba62dd71b530b03aa2130238bf2b..7e32927b67721ae63a960b60b714c2daaa75ecc6 100644 (file)
@@ -1,5 +1,7 @@
 2009-10-02  Roland McGrath  <roland@redhat.com>
 
+       * c++/subr.hh (subr::stackish): New template type.
+
        * c++/dwarf_comparator: Fix overload magic to distinguish reference
        comparisons from child comparisons.
 
index c080aa8a453897377257f35702d497bd592b7a55..d8daa80fff742d1304a451f4a14ccd25c9c19225 100644 (file)
@@ -15,6 +15,7 @@
 #include <tr1/unordered_set>
 #include <vector>
 #include <deque>
+#include <stack>
 #include <algorithm>
 #include <utility>
 #include <stdexcept>
@@ -1225,11 +1226,6 @@ namespace elfutils
        return *_m_head;
       }
 
-      inline const value_type &const_top ()
-      {
-       return const_cast<const sharing_stack *> (this)->top ();
-      }
-
       inline const value_type &const_top () const
       {
        return top ();
@@ -1359,6 +1355,54 @@ namespace elfutils
       }
     };
 
+    // Compatible with sharing_stack, but actually a std::stack.
+    template<typename T, typename container_type = std::deque<T> >
+    struct stackish
+      : public std::stack<T, container_type>
+    {
+      inline const T &const_top () const
+      {
+       return this->top ();
+      }
+
+      inline void clear ()
+      {
+       this->c.clear ();
+      }
+
+      typedef typename container_type::const_reverse_iterator
+      const_reverse_iterator;
+
+      inline const_reverse_iterator rbegin () const
+      {
+       return this->c.rbegin ();
+      }
+
+      inline const_reverse_iterator rend () const
+      {
+       return this->c.rend ();
+      }
+
+      template<typename other_value_type, typename other_container_type,
+              typename pred_type>
+      inline bool
+      equal (const stackish<other_value_type, other_container_type> &other,
+            pred_type &pred, typename container_type::size_type skip = 0) const
+      {
+       if (other.size () != this->size ())
+         return false;
+
+       typename container_type::const_reverse_iterator a = this->rbegin ();
+       typename other_container_type::const_reverse_iterator b
+         = other.rbegin ();
+
+       std::advance (a, skip);
+       std::advance (b, skip);
+
+       return std::equal (a, this->rend (), b, pred);
+      }
+    };
+
     /* This is a dummy you can template/syntactically use in
        place of std::cout et al for disabled debugging spew.  */
     struct nostream