ADT: Use perfect forwarding in StringMapEntry::Create()
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 13 Nov 2014 23:23:02 +0000 (23:23 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 13 Nov 2014 23:23:02 +0000 (23:23 +0000)
Now you can pass references into constructors.

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

include/llvm/ADT/StringMap.h

index c40e5e2b3d874f6641ae115986dd5ac4f45c39fa..17d5c0d609198e7485cdb647f599c813e7836391 100644 (file)
@@ -117,8 +117,9 @@ public:
 
   explicit StringMapEntry(unsigned strLen)
     : StringMapEntryBase(strLen), second() {}
-  StringMapEntry(unsigned strLen, ValueTy V)
-      : StringMapEntryBase(strLen), second(std::move(V)) {}
+  template <class InitTy>
+  StringMapEntry(unsigned strLen, InitTy &&V)
+      : StringMapEntryBase(strLen), second(std::forward<InitTy>(V)) {}
 
   StringRef getKey() const {
     return StringRef(getKeyData(), getKeyLength());
@@ -138,10 +139,9 @@ public:
 
   /// Create - Create a StringMapEntry for the specified key and default
   /// construct the value.
-  template<typename AllocatorTy, typename InitType>
-  static StringMapEntry *Create(StringRef Key,
-                                AllocatorTy &Allocator,
-                                InitType InitVal) {
+  template <typename AllocatorTy, typename InitType>
+  static StringMapEntry *Create(StringRef Key, AllocatorTy &Allocator,
+                                InitType &&InitVal) {
     unsigned KeyLength = Key.size();
 
     // Allocate a new item with space for the string at the end and a null
@@ -154,7 +154,7 @@ public:
       static_cast<StringMapEntry*>(Allocator.Allocate(AllocSize,Alignment));
 
     // Default construct the value.
-    new (NewItem) StringMapEntry(KeyLength, std::move(InitVal));
+    new (NewItem) StringMapEntry(KeyLength, std::forward<InitType>(InitVal));
 
     // Copy the string information.
     char *StrBuffer = const_cast<char*>(NewItem->getKeyData());