Title: [223041] trunk
Revision
223041
Author
[email protected]
Date
2017-10-08 21:08:33 -0700 (Sun, 08 Oct 2017)

Log Message

It should be possible to create a ListHashSet with a std::initializer_list.
https://bugs.webkit.org/show_bug.cgi?id=178070

Patch by Sam Weinig <[email protected]> on 2017-10-08
Reviewed by Darin Adler.

Source/WTF:

* wtf/ListHashSet.h:
(WTF::U>::ListHashSet):
Add a constructor that takes a std::initializer_list.

Tools:

* TestWebKitAPI/Tests/WTF/ListHashSet.cpp:
(TestWebKitAPI::TEST):
Add a test for using std::initializer_list with ListHashSet.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (223040 => 223041)


--- trunk/Source/WTF/ChangeLog	2017-10-09 03:43:17 UTC (rev 223040)
+++ trunk/Source/WTF/ChangeLog	2017-10-09 04:08:33 UTC (rev 223041)
@@ -1,5 +1,16 @@
 2017-10-08  Sam Weinig  <[email protected]>
 
+        It should be possible to create a ListHashSet with a std::initializer_list.
+        https://bugs.webkit.org/show_bug.cgi?id=178070
+
+        Reviewed by Darin Adler.
+
+        * wtf/ListHashSet.h:
+        (WTF::U>::ListHashSet):
+        Add a constructor that takes a std::initializer_list.
+
+2017-10-08  Sam Weinig  <[email protected]>
+
         Address additional feedback from Darin for r223039 and sort the using declarations.
 
         * wtf/Vector.h:

Modified: trunk/Source/WTF/wtf/ListHashSet.h (223040 => 223041)


--- trunk/Source/WTF/wtf/ListHashSet.h	2017-10-09 03:43:17 UTC (rev 223040)
+++ trunk/Source/WTF/wtf/ListHashSet.h	2017-10-09 04:08:33 UTC (rev 223041)
@@ -69,6 +69,7 @@
     typedef HashTableAddResult<iterator> AddResult;
 
     ListHashSet() = default;
+    ListHashSet(std::initializer_list<ValueType>);
     ListHashSet(const ListHashSet&);
     ListHashSet(ListHashSet&&);
     ListHashSet& operator=(const ListHashSet&);
@@ -305,7 +306,15 @@
     }
 };
 
+
 template<typename T, typename U>
+inline ListHashSet<T, U>::ListHashSet(std::initializer_list<T> initializerList)
+{
+    for (const auto& value : initializerList)
+        add(value);
+}
+
+template<typename T, typename U>
 inline ListHashSet<T, U>::ListHashSet(const ListHashSet& other)
 {
     for (auto it = other.begin(), end = other.end(); it != end; ++it)

Modified: trunk/Tools/ChangeLog (223040 => 223041)


--- trunk/Tools/ChangeLog	2017-10-09 03:43:17 UTC (rev 223040)
+++ trunk/Tools/ChangeLog	2017-10-09 04:08:33 UTC (rev 223041)
@@ -1,5 +1,16 @@
 2017-10-08  Sam Weinig  <[email protected]>
 
+        It should be possible to create a ListHashSet with a std::initializer_list.
+        https://bugs.webkit.org/show_bug.cgi?id=178070
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WTF/ListHashSet.cpp:
+        (TestWebKitAPI::TEST):
+        Add a test for using std::initializer_list with ListHashSet.
+
+2017-10-08  Sam Weinig  <[email protected]>
+
         There should be a version of copyToVector that returns a Vector, rather than using an out parameter
         https://bugs.webkit.org/show_bug.cgi?id=177732
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp (223040 => 223041)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp	2017-10-09 03:43:17 UTC (rev 223040)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp	2017-10-09 04:08:33 UTC (rev 223041)
@@ -348,4 +348,29 @@
     ++iterator;
 }
 
+TEST(WTF_ListHashSet, InitializerListConstuctor)
+{
+    ListHashSet<int> set { 1, 2, 3 };
+    ASSERT_EQ(3U, set.size());
+    auto iterator = set.begin();
+    ASSERT_EQ(1, *iterator);
+    ++iterator;
+    ASSERT_EQ(2, *iterator);
+    ++iterator;
+    ASSERT_EQ(3, *iterator);
+    ++iterator;
+
+    set = { 4, 5, 6, 7 };
+    ASSERT_EQ(4U, set.size());
+    iterator = set.begin();
+    ASSERT_EQ(4, *iterator);
+    ++iterator;
+    ASSERT_EQ(5, *iterator);
+    ++iterator;
+    ASSERT_EQ(6, *iterator);
+    ++iterator;
+    ASSERT_EQ(7, *iterator);
+    ++iterator;
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to