diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-08-12 03:35:33 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-08-12 03:35:33 +0000 |
| commit | fb14ed0777b25eab6a29b4cd596964df5194eae5 (patch) | |
| tree | 81f54aad0c9d5325909829a54b35f01f65fe6679 | |
| parent | 7e103d92cc2b6d3e6d53a6353885cac9f00be84f (diff) | |
| download | bcm5719-llvm-fb14ed0777b25eab6a29b4cd596964df5194eae5.tar.gz bcm5719-llvm-fb14ed0777b25eab6a29b4cd596964df5194eae5.zip | |
ADT: Add ilist_iterator conversions to/from ilist_node
Allow an ilist_iterator to be constructed from an ilist_node, and give
access to the underlying ilist_node as well.
This will be used immediately in lld to support a type-erasure use case.
Longer term, they'll stick around once the iterator is using
ilist_node<NodeTy>* instead of NodeTy*.
llvm-svn: 278467
| -rw-r--r-- | llvm/include/llvm/ADT/ilist.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/ilist.h b/llvm/include/llvm/ADT/ilist.h index 8e4d45dfef2..a7c72e86ced 100644 --- a/llvm/include/llvm/ADT/ilist.h +++ b/llvm/include/llvm/ADT/ilist.h @@ -185,6 +185,15 @@ struct ilist_traits : public ilist_default_traits<NodeTy> {}; template<typename Ty> struct ilist_traits<const Ty> : public ilist_traits<Ty> {}; +namespace ilist_detail { +template <class NodeTy> struct ConstCorrectNodeType { + typedef ilist_node<NodeTy> type; +}; +template <class NodeTy> struct ConstCorrectNodeType<const NodeTy> { + typedef const ilist_node<NodeTy> type; +}; +} // end namespace ilist_detail + //===----------------------------------------------------------------------===// // Iterator for intrusive list. // @@ -201,10 +210,18 @@ public: typedef typename super::pointer pointer; typedef typename super::reference reference; + typedef typename ilist_detail::ConstCorrectNodeType<NodeTy>::type node_type; + typedef node_type *node_pointer; + typedef node_type &node_reference; + private: pointer NodePtr; public: + /// Create from an ilist_node. + explicit ilist_iterator(node_reference N) + : NodePtr(static_cast<NodeTy *>(&N)) {} + explicit ilist_iterator(pointer NP) : NodePtr(NP) {} explicit ilist_iterator(reference NR) : NodePtr(&NR) {} ilist_iterator() : NodePtr(nullptr) {} @@ -259,6 +276,9 @@ public: return tmp; } + /// Get the underlying ilist_node. + node_pointer getNodePtr() const { return static_cast<node_pointer>(NodePtr); } + // Internal interface, do not use... pointer getNodePtrUnchecked() const { return NodePtr; } }; |

