Add an initializer list constructor to Deque
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Feb 2015 18:46:04 +0000 (18:46 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Feb 2015 18:46:04 +0000 (18:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141565

Reviewed by Andreas Kling.

Source/WTF:

* wtf/Deque.h:
(WTF::inlineCapacity>::Deque):

Tools:

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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180059 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/Deque.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/Deque.cpp

index f46247f..9b65543 100644 (file)
@@ -1,5 +1,15 @@
 2015-02-13  Anders Carlsson  <andersca@apple.com>
 
+        Add an initializer list constructor to Deque
+        https://bugs.webkit.org/show_bug.cgi?id=141565
+
+        Reviewed by Andreas Kling.
+
+        * wtf/Deque.h:
+        (WTF::inlineCapacity>::Deque):
+
+2015-02-13  Anders Carlsson  <andersca@apple.com>
+
         Re-indent Deque.h
 
         Rubber-stamped by Antti Koivisto.
index bad4310..a62048e 100644 (file)
@@ -52,6 +52,7 @@ public:
     typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
 
     Deque();
+    Deque(std::initializer_list<T>);
     Deque(const Deque<T, inlineCapacity>&);
     Deque& operator=(const Deque<T, inlineCapacity>&);
     ~Deque();
@@ -273,6 +274,14 @@ inline Deque<T, inlineCapacity>::Deque()
 }
 
 template<typename T, size_t inlineCapacity>
+inline Deque<T, inlineCapacity>::Deque(std::initializer_list<T> initializerList)
+    : Deque()
+{
+    for (auto& element : initializerList)
+        append(element);
+}
+
+template<typename T, size_t inlineCapacity>
 inline Deque<T, inlineCapacity>::Deque(const Deque<T, inlineCapacity>& other)
     : m_start(other.m_start)
     , m_end(other.m_end)
index ae974aa..92ff693 100644 (file)
@@ -1,3 +1,13 @@
+2015-02-13  Anders Carlsson  <andersca@apple.com>
+
+        Add an initializer list constructor to Deque
+        https://bugs.webkit.org/show_bug.cgi?id=141565
+
+        Reviewed by Andreas Kling.
+
+        * TestWebKitAPI/Tests/WTF/Deque.cpp:
+        (TestWebKitAPI::TEST):
+
 2015-02-13  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [buildbot] Remove buildJSCTool cruft from master.cfg
index 4cb9dcd..874f5c4 100644 (file)
@@ -54,6 +54,28 @@ TEST(WTF_Deque, Iterator)
     EXPECT_TRUE(end == it);
 }
 
+TEST(WTF_Deque, InitializerList)
+{
+    Deque<int> deque = { 1, 2, 3, 4 };
+
+    EXPECT_EQ(4u, deque.size());
+
+    auto it = deque.begin();
+    auto end = deque.end();
+    EXPECT_TRUE(end != it);
+
+    EXPECT_EQ(1, *it);
+    ++it;
+    EXPECT_EQ(2, *it);
+    ++it;
+    EXPECT_EQ(3, *it);
+    ++it;
+    EXPECT_EQ(4, *it);
+    ++it;
+
+    EXPECT_TRUE(end == it);
+}
+
 TEST(WTF, DequeReverseIterator)
 {
     Deque<int> deque;