Title: [156204] trunk/Source/WTF
Revision
156204
Author
[email protected]
Date
2013-09-20 14:58:46 -0700 (Fri, 20 Sep 2013)

Log Message

Add an implementation of std::index_sequence from C++14
https://bugs.webkit.org/show_bug.cgi?id=121718

Reviewed by Ryosuke Niwa.

This will make it easier to do things like pack expansion of tuple elements.

* wtf/StdLibExtras.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (156203 => 156204)


--- trunk/Source/WTF/ChangeLog	2013-09-20 21:56:10 UTC (rev 156203)
+++ trunk/Source/WTF/ChangeLog	2013-09-20 21:58:46 UTC (rev 156204)
@@ -1,3 +1,14 @@
+2013-09-20  Anders Carlsson  <[email protected]>
+
+        Add an implementation of std::index_sequence from C++14
+        https://bugs.webkit.org/show_bug.cgi?id=121718
+
+        Reviewed by Ryosuke Niwa.
+
+        This will make it easier to do things like pack expansion of tuple elements.
+
+        * wtf/StdLibExtras.h:
+
 2013-09-20  Allan Sandfeld Jensen  <[email protected]>
 
         Atomics.h does not build on MinGW

Modified: trunk/Source/WTF/wtf/StdLibExtras.h (156203 => 156204)


--- trunk/Source/WTF/wtf/StdLibExtras.h	2013-09-20 21:56:10 UTC (rev 156203)
+++ trunk/Source/WTF/wtf/StdLibExtras.h	2013-09-20 21:58:46 UTC (rev 156204)
@@ -306,12 +306,8 @@
 }
 
 
-// For standard libraries that do not yet include it, this adds the std::make_unique
-// type. It is defined in the same namespaces as it would be in library that had the
-// support.
-
+// This adds various C++14 features for versions of the STL that may not yet have them.
 namespace std {
-
     template<class T> struct _Unique_if {
         typedef unique_ptr<T> _Single_object;
     };
@@ -362,6 +358,26 @@
     make_unique(Args&&...) = delete;
 #endif
 
+#if COMPILER_SUPPORTS(CXX_VARIADIC_TEMPLATES)
+    // Compile-time integer sequences
+    // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3658.html
+    // (Note that we only implement index_sequence, and not the more generic integer_sequence).
+    template<size_t... indexes> struct index_sequence {
+        static size_t size() { return sizeof...(indexes); }
+    };
+
+    template<size_t currentIndex, size_t...indexes> struct make_index_sequence_helper;
+
+    template<size_t...indexes> struct make_index_sequence_helper<0, indexes...> {
+        typedef std::index_sequence<indexes...> type;
+    };
+
+    template<size_t currentIndex, size_t...indexes> struct make_index_sequence_helper {
+        typedef typename make_index_sequence_helper<currentIndex - 1, currentIndex - 1, indexes...>::type type;
+    };
+
+    template<size_t length> struct make_index_sequence : public make_index_sequence_helper<length>::type { };
+#endif
 }
 
 using WTF::KB;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to