[PATCH] D70735: [ADT] Add non-const operator* to iterator_adaptor_base and df_iterator.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 26 11:17:19 PST 2019


fhahn created this revision.
fhahn added reviewers: jfb, bogner, dblaikie, asbirlea.
Herald added a subscriber: dexonsmith.
Herald added a project: LLVM.

The missing non-const operator* implementation are causing issues when
using filter_iterator with df_iterator: without the non-const
implementation, we can only return const references to the underlying
values.

This patch also adjusts the return type of operator* cont in
interator_adaptor_base.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70735

Files:
  llvm/include/llvm/ADT/DepthFirstIterator.h
  llvm/include/llvm/ADT/iterator.h


Index: llvm/include/llvm/ADT/iterator.h
===================================================================
--- llvm/include/llvm/ADT/iterator.h
+++ llvm/include/llvm/ADT/iterator.h
@@ -268,7 +268,8 @@
     return I < RHS.I;
   }
 
-  ReferenceT operator*() const { return *I; }
+  const ReferenceT operator*() const { return *I; }
+  ReferenceT operator*() { return *I; }
 };
 
 /// An iterator type that allows iterating over the pointees via some
Index: llvm/include/llvm/ADT/DepthFirstIterator.h
===================================================================
--- llvm/include/llvm/ADT/DepthFirstIterator.h
+++ llvm/include/llvm/ADT/DepthFirstIterator.h
@@ -164,6 +164,7 @@
   bool operator!=(const df_iterator &x) const { return !(*this == x); }
 
   const NodeRef &operator*() const { return VisitStack.back().first; }
+  NodeRef &operator*() { return VisitStack.back().first; }
 
   // This is a nonstandard operator-> that dereferences the pointer an extra
   // time... so that you can actually call methods ON the Node, because


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70735.231112.patch
Type: text/x-patch
Size: 1042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191126/e8ed33f8/attachment.bin>


More information about the llvm-commits mailing list