Title: [160400] trunk
Revision
160400
Author
[email protected]
Date
2013-12-10 17:08:11 -0800 (Tue, 10 Dec 2013)

Log Message

Add a HashMap constructor that takes an initializer list
https://bugs.webkit.org/show_bug.cgi?id=125551

Reviewed by Dan Bernstein.

Source/WTF:

* wtf/HashMap.h:
(WTF::HashMap::HashMap):

Tools:

* TestWebKitAPI/Tests/WTF/HashMap.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (160399 => 160400)


--- trunk/Source/WTF/ChangeLog	2013-12-11 01:01:31 UTC (rev 160399)
+++ trunk/Source/WTF/ChangeLog	2013-12-11 01:08:11 UTC (rev 160400)
@@ -1,3 +1,13 @@
+2013-12-10  Anders Carlsson  <[email protected]>
+
+        Add a HashMap constructor that takes an initializer list
+        https://bugs.webkit.org/show_bug.cgi?id=125551
+
+        Reviewed by Dan Bernstein.
+
+        * wtf/HashMap.h:
+        (WTF::HashMap::HashMap):
+
 2013-12-10  Laszlo Vidacs  <[email protected]>
 
         Use std::array when computing MD5 checksum

Modified: trunk/Source/WTF/wtf/HashMap.h (160399 => 160400)


--- trunk/Source/WTF/wtf/HashMap.h	2013-12-11 01:01:31 UTC (rev 160399)
+++ trunk/Source/WTF/wtf/HashMap.h	2013-12-11 01:08:11 UTC (rev 160400)
@@ -67,6 +67,18 @@
     typedef typename HashTableType::AddResult AddResult;
 
 public:
+    HashMap()
+    {
+    }
+
+#if COMPILER_SUPPORTS(CXX_GENERALIZED_INITIALIZERS)
+    HashMap(std::initializer_list<KeyValuePairType> initializerList)
+    {
+        for (const auto& keyValuePair : initializerList)
+            add(keyValuePair.key, keyValuePair.value);
+    }
+#endif
+
     void swap(HashMap&);
 
     int size() const;

Modified: trunk/Tools/ChangeLog (160399 => 160400)


--- trunk/Tools/ChangeLog	2013-12-11 01:01:31 UTC (rev 160399)
+++ trunk/Tools/ChangeLog	2013-12-11 01:08:11 UTC (rev 160400)
@@ -1,3 +1,13 @@
+2013-12-10  Anders Carlsson  <[email protected]>
+
+        Add a HashMap constructor that takes an initializer list
+        https://bugs.webkit.org/show_bug.cgi?id=125551
+
+        Reviewed by Dan Bernstein.
+
+        * TestWebKitAPI/Tests/WTF/HashMap.cpp:
+        (TestWebKitAPI::TEST):
+
 2013-12-10  Laszlo Vidacs  <[email protected]>
 
         Use std::array when computing MD5 checksum

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp (160399 => 160400)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp	2013-12-11 01:01:31 UTC (rev 160399)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp	2013-12-11 01:08:11 UTC (rev 160400)
@@ -26,6 +26,7 @@
 #include "config.h"
 
 #include "MoveOnly.h"
+#include <string>
 #include <wtf/HashMap.h>
 #include <wtf/text/StringHash.h>
 
@@ -129,4 +130,24 @@
     ASSERT_TRUE(moveOnlyKeys.isEmpty());
 }
 
+#if COMPILER_SUPPORTS(CXX_GENERALIZED_INITIALIZERS)
+TEST(WTF_HashMap, InitializerList)
+{
+    HashMap<unsigned, std::string> map = {
+        { 1, "one" },
+        { 2, "two" },
+        { 3, "three" },
+        { 4, "four" },
+    };
+
+    EXPECT_EQ(4, map.size());
+
+    EXPECT_EQ("one", map.get(1));
+    EXPECT_EQ("two", map.get(2));
+    EXPECT_EQ("three", map.get(3));
+    EXPECT_EQ("four", map.get(4));
+    EXPECT_EQ(std::string(), map.get(5));
+}
+#endif
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to