Iterator traits and swap. closes PR6548 and PR6549
authorAndrew Lenharth <andrewl@lenharth.org>
Mon, 8 Mar 2010 20:45:52 +0000 (20:45 +0000)
committerAndrew Lenharth <andrewl@lenharth.org>
Mon, 8 Mar 2010 20:45:52 +0000 (20:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97974 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/DenseMap.h
include/llvm/ADT/DenseSet.h

index 735090627c3efb17dee6199d4510a4e51f7fc58c..393473bd97b82974501079be06d94f3a8d3da1e0 100644 (file)
@@ -192,6 +192,13 @@ public:
     return true;
   }
 
+  void swap(DenseMap& RHS) {
+    std::swap(NumBuckets, RHS.NumBuckets);
+    std::swap(Buckets, RHS.Buckets);
+    std::swap(NumEntries, RHS.NumEntries);
+    std::swap(NumTombstones, RHS.NumTombstones);
+  }
+
   value_type& FindAndConstruct(const KeyT &Key) {
     BucketT *TheBucket;
     if (LookupBucketFor(Key, TheBucket))
index 0898b968aca9101524b770ec44199ff35ec88ef9..938833866fcdb1447f4c7905871468391e869d4e 100644 (file)
@@ -45,6 +45,10 @@ public:
     return TheMap.erase(V);
   }
 
+  void swap(DenseSet& RHS) {
+    TheMap.swap(RHS.TheMap);
+  }
+
   DenseSet &operator=(const DenseSet &RHS) {
     TheMap = RHS.TheMap;
     return *this;
@@ -55,6 +59,12 @@ public:
   class Iterator {
     typename MapTy::iterator I;
   public:
+    typedef typename MapTy::iterator::difference_type difference_type;
+    typedef ValueT value_type;
+    typedef value_type *pointer;
+    typedef value_type &reference;
+    typedef std::forward_iterator_tag iterator_category;
+
     Iterator(const typename MapTy::iterator &i) : I(i) {}
 
     ValueT& operator*() { return I->first; }
@@ -68,6 +78,12 @@ public:
   class ConstIterator {
     typename MapTy::const_iterator I;
   public:
+    typedef typename MapTy::const_iterator::difference_type difference_type;
+    typedef ValueT value_type;
+    typedef value_type *pointer;
+    typedef value_type &reference;
+    typedef std::forward_iterator_tag iterator_category;
+
     ConstIterator(const typename MapTy::const_iterator &i) : I(i) {}
 
     const ValueT& operator*() { return I->first; }