]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
xlist: implement const_iterator
authorJohn Spray <john.spray@redhat.com>
Fri, 5 Sep 2014 13:10:40 +0000 (14:10 +0100)
committerJohn Spray <john.spray@redhat.com>
Mon, 15 Sep 2014 14:05:14 +0000 (15:05 +0100)
Signed-off-by: John Spray <john.spray@redhat.com>
src/include/xlist.h

index 5384561327a56f805df0b7c56184b2725b7a92a9..26a6b9d5746c2bb777453f79e56a4b0478ff0183 100644 (file)
@@ -161,6 +161,24 @@ public:
 
   iterator begin() { return iterator(_front); }
   iterator end() { return iterator(NULL); }
+
+  class const_iterator {
+  private:
+    item *cur;
+  public:
+    const_iterator(item *i = 0) : cur(i) {}
+    const T operator*() { return static_cast<const T>(cur->_item); }
+    const_iterator& operator++() {
+      assert(cur);
+      assert(cur->_list);
+      cur = cur->_next;
+      return *this;
+    }
+    bool end() const { return cur == 0; }
+  };
+
+  const_iterator begin() const { return const_iterator(_front); }
+  const_iterator end() const { return const_iterator(NULL); }
 };