[Support] Add StringMap::swap() and a default ctor for iterators
authorReid Kleckner <reid@kleckner.net>
Wed, 22 May 2013 17:10:11 +0000 (17:10 +0000)
committerReid Kleckner <reid@kleckner.net>
Wed, 22 May 2013 17:10:11 +0000 (17:10 +0000)
This makes StringMap<> more compatible with std::map<std::string, ...>.

Differential Revision: http://llvm-reviews.chandlerc.com/D842

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182487 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringMap.h

index d01437b61c2bb8bcaeff0baf851ed07805f61850..2e07268596ae3a834cf8f5494461421607efe5f0 100644 (file)
@@ -102,6 +102,13 @@ public:
 
   bool empty() const { return NumItems == 0; }
   unsigned size() const { return NumItems; }
+
+  void swap(StringMapImpl &Other) {
+    std::swap(TheTable, Other.TheTable);
+    std::swap(NumBuckets, Other.NumBuckets);
+    std::swap(NumItems, Other.NumItems);
+    std::swap(NumTombstones, Other.NumTombstones);
+  }
 };
 
 /// StringMapEntry - This is used to represent one value that is inserted into
@@ -409,6 +416,8 @@ protected:
 public:
   typedef StringMapEntry<ValueTy> value_type;
 
+  StringMapConstIterator() : Ptr(0) { }
+
   explicit StringMapConstIterator(StringMapEntryBase **Bucket,
                                   bool NoAdvance = false)
   : Ptr(Bucket) {
@@ -448,6 +457,7 @@ private:
 template<typename ValueTy>
 class StringMapIterator : public StringMapConstIterator<ValueTy> {
 public:
+  StringMapIterator() : StringMapConstIterator() {}
   explicit StringMapIterator(StringMapEntryBase **Bucket,
                              bool NoAdvance = false)
     : StringMapConstIterator<ValueTy>(Bucket, NoAdvance) {