Title: [159202] trunk
- Revision
- 159202
- Author
- [email protected]
- Date
- 2013-11-13 09:35:30 -0800 (Wed, 13 Nov 2013)
Log Message
Add a Vector constructor that takes an std::initializer_list
https://bugs.webkit.org/show_bug.cgi?id=124287
Reviewed by Antti Koivisto.
Source/WTF:
* wtf/Compiler.h:
* wtf/Vector.h:
(WTF::Vector::Vector):
Tools:
* TestWebKitAPI/Tests/WTF/Vector.cpp:
(TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (159201 => 159202)
--- trunk/Source/WTF/ChangeLog 2013-11-13 17:26:54 UTC (rev 159201)
+++ trunk/Source/WTF/ChangeLog 2013-11-13 17:35:30 UTC (rev 159202)
@@ -1,3 +1,14 @@
+2013-11-13 Anders Carlsson <[email protected]>
+
+ Add a Vector constructor that takes an std::initializer_list
+ https://bugs.webkit.org/show_bug.cgi?id=124287
+
+ Reviewed by Antti Koivisto.
+
+ * wtf/Compiler.h:
+ * wtf/Vector.h:
+ (WTF::Vector::Vector):
+
2013-11-12 Brent Fulgham <[email protected]>
[Win] Unreviewed gardening.
Modified: trunk/Source/WTF/wtf/Compiler.h (159201 => 159202)
--- trunk/Source/WTF/wtf/Compiler.h 2013-11-13 17:26:54 UTC (rev 159201)
+++ trunk/Source/WTF/wtf/Compiler.h 2013-11-13 17:35:30 UTC (rev 159202)
@@ -54,6 +54,7 @@
#define WTF_COMPILER_SUPPORTS_CXX_STRONG_ENUMS __has_feature(cxx_strong_enums)
#define WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS __has_feature(cxx_reference_qualified_functions)
#define WTF_COMPILER_SUPPORTS_CXX_AUTO_TYPE __has_feature(cxx_auto_type)
+#define WTF_COMPILER_SUPPORTS_CXX_GENERALIZED_INITIALIZERS __has_feature(cxx_generalized_initializers)
/* Disable final on versions of Apple clang earlier than 4.2 to avoid bugs like http://webkit.org/b/119165 */
#if defined(__APPLE__) && (__clang_major__ < 4 || (__clang_major__ == 4 && __clang_minor__ < 2))
Modified: trunk/Source/WTF/wtf/Vector.h (159201 => 159202)
--- trunk/Source/WTF/wtf/Vector.h 2013-11-13 17:26:54 UTC (rev 159201)
+++ trunk/Source/WTF/wtf/Vector.h 2013-11-13 17:35:30 UTC (rev 159202)
@@ -548,6 +548,15 @@
TypeOperations::uninitializedFill(begin(), end(), val);
}
+#if COMPILER_SUPPORTS(CXX_GENERALIZED_INITIALIZERS)
+ Vector(std::initializer_list<T> initializerList)
+ {
+ reserveInitialCapacity(initializerList.size());
+ for (const auto& element : initializerList)
+ uncheckedAppend(element);
+ }
+#endif
+
~Vector()
{
if (m_size)
Modified: trunk/Tools/ChangeLog (159201 => 159202)
--- trunk/Tools/ChangeLog 2013-11-13 17:26:54 UTC (rev 159201)
+++ trunk/Tools/ChangeLog 2013-11-13 17:35:30 UTC (rev 159202)
@@ -1,3 +1,13 @@
+2013-11-13 Anders Carlsson <[email protected]>
+
+ Add a Vector constructor that takes an std::initializer_list
+ https://bugs.webkit.org/show_bug.cgi?id=124287
+
+ Reviewed by Antti Koivisto.
+
+ * TestWebKitAPI/Tests/WTF/Vector.cpp:
+ (TestWebKitAPI::TEST):
+
2013-11-13 Mario Sanchez Prada <[email protected]>
Unreviewed GTK gardening. Updated rebaseline unit tests to include WK2 bot.
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp (159201 => 159202)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp 2013-11-13 17:26:54 UTC (rev 159201)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp 2013-11-13 17:35:30 UTC (rev 159202)
@@ -83,6 +83,19 @@
vector.append(const_cast<const unsigned&>(vector.last()));
}
+#if COMPILER_SUPPORTS(CXX_GENERALIZED_INITIALIZERS)
+TEST(WTF_Vector, InitializerList)
+{
+ Vector<int> vector = { 1, 2, 3, 4 };
+ EXPECT_EQ(4U, vector.size());
+
+ EXPECT_EQ(1, vector[0]);
+ EXPECT_EQ(2, vector[1]);
+ EXPECT_EQ(3, vector[2]);
+ EXPECT_EQ(4, vector[3]);
+}
+#endif
+
TEST(WTF_Vector, Reverse)
{
Vector<int> intVector;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes