buffer: fix the traits of list::iterator
authorKefu Chai <kchai@redhat.com>
Mon, 26 Nov 2018 17:47:07 +0000 (01:47 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 27 Nov 2018 16:26:02 +0000 (00:26 +0800)
before this change, the constness of value, pointer, etc traits of
list::iterator was wrong.  also, because std::iterator is deprecated
in C++17, we need to define the traits manually. so, do this change.

these traits could be potentially used anywhere in the source tree.
but a noteworthy user is is_const_iterator<> in denc.h.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/include/buffer.h

index 368dc7fbd56db66197f016b2f683c7985c516dfc..a984cea4946e213ec1604c59ed45a2c8789cdee9 100644 (file)
@@ -395,8 +395,7 @@ namespace buffer CEPH_BUFFER_API {
 
   private:
     template <bool is_const>
-    class CEPH_BUFFER_API iterator_impl
-      : public std::iterator<std::forward_iterator_tag, char> {
+    class CEPH_BUFFER_API iterator_impl {
     protected:
       typedef typename std::conditional<is_const,
                                        const list,
@@ -407,6 +406,12 @@ namespace buffer CEPH_BUFFER_API {
       typedef typename std::conditional<is_const,
                                        typename std::list<ptr>::const_iterator,
                                        typename std::list<ptr>::iterator>::type list_iter_t;
+      using iterator_category = std::forward_iterator_tag;
+      using value_type = typename std::conditional<is_const, const char, char>::type;
+      using difference_type = std::ptrdiff_t;
+      using pointer = typename std::add_pointer<value_type>::type;
+      using reference = typename std::add_lvalue_reference<value_type>::type;
+
       bl_t* bl;
       list_t* ls;  // meh.. just here to avoid an extra pointer dereference..
       unsigned off; // in bl