<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[242932] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/242932">242932</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2019-03-13 19:46:16 -0700 (Wed, 13 Mar 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add utility function to allow easy reverse range-based iteration of a container
https://bugs.webkit.org/show_bug.cgi?id=195542

Patch by Sam Weinig <sam@webkit.org> on 2019-03-13
Reviewed by Antti Koivisto.

Source/WTF:

Add functions to create an IteratorRange<T> that will iterate a container backwards. It
works with any container that is compatible with std::rbegin() and std::rend(). It is
expected to be used in conjunction with range-based for-loops like so:

for (auto& value : WTF::makeReversedRange(myContainer))
    ...

* wtf/IteratorRange.h:
(WTF::makeReversedRange):

Tools:

* TestWebKitAPI/CMakeLists.txt:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/IteratorRange.cpp: Added.
(TestWebKitAPI::TEST):
Add test to ensure WTF::makeReversedRange() works correctly and uses the correct types.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfIteratorRangeh">trunk/Source/WTF/wtf/IteratorRange.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPICMakeListstxt">trunk/Tools/TestWebKitAPI/CMakeLists.txt</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWTFIteratorRangecpp">trunk/Tools/TestWebKitAPI/Tests/WTF/IteratorRange.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (242931 => 242932)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog       2019-03-14 01:42:12 UTC (rev 242931)
+++ trunk/Source/WTF/ChangeLog  2019-03-14 02:46:16 UTC (rev 242932)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2019-03-13  Sam Weinig  <sam@webkit.org>
+
+        Add utility function to allow easy reverse range-based iteration of a container
+        https://bugs.webkit.org/show_bug.cgi?id=195542
+
+        Reviewed by Antti Koivisto.
+
+        Add functions to create an IteratorRange<T> that will iterate a container backwards. It
+        works with any container that is compatible with std::rbegin() and std::rend(). It is
+        expected to be used in conjunction with range-based for-loops like so:
+
+        for (auto& value : WTF::makeReversedRange(myContainer)) 
+            ...
+
+        * wtf/IteratorRange.h:
+        (WTF::makeReversedRange):
+
</ins><span class="cx"> 2019-03-13  Keith Rollin  <krollin@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Add support for new StagedFrameworks layout
</span></span></pre></div>
<a id="trunkSourceWTFwtfIteratorRangeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/IteratorRange.h (242931 => 242932)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/IteratorRange.h     2019-03-14 01:42:12 UTC (rev 242931)
+++ trunk/Source/WTF/wtf/IteratorRange.h        2019-03-14 02:46:16 UTC (rev 242932)
</span><span class="lines">@@ -25,6 +25,8 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><ins>+#include <iterator>
+
</ins><span class="cx"> namespace WTF {
</span><span class="cx"> 
</span><span class="cx"> template<typename Iterator>
</span><span class="lines">@@ -50,6 +52,18 @@
</span><span class="cx">     return IteratorRange<Iterator>(std::forward<Iterator>(begin), std::forward<Iterator>(end));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+template<typename Container>
+IteratorRange<typename Container::reverse_iterator> makeReversedRange(Container& container)
+{
+    return makeIteratorRange(std::rbegin(container), std::rend(container));
+}
+
+template<typename Container>
+IteratorRange<typename Container::const_reverse_iterator> makeReversedRange(const Container& container)
+{
+    return makeIteratorRange(std::crbegin(container), std::crend(container));
+}
+
</ins><span class="cx"> template<typename Container, typename Iterator>
</span><span class="cx"> class SizedIteratorRange {
</span><span class="cx"> public:
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (242931 => 242932)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2019-03-14 01:42:12 UTC (rev 242931)
+++ trunk/Tools/ChangeLog       2019-03-14 02:46:16 UTC (rev 242932)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2019-03-13  Sam Weinig  <sam@webkit.org>
+
+        Add utility function to allow easy reverse range-based iteration of a container
+        https://bugs.webkit.org/show_bug.cgi?id=195542
+
+        Reviewed by Antti Koivisto.
+
+        * TestWebKitAPI/CMakeLists.txt:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WTF/IteratorRange.cpp: Added.
+        (TestWebKitAPI::TEST):
+        Add test to ensure WTF::makeReversedRange() works correctly and uses the correct types.
+
</ins><span class="cx"> 2019-03-13  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Use a ServiceWorker process per registrable domain
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPICMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (242931 => 242932)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/CMakeLists.txt 2019-03-14 01:42:12 UTC (rev 242931)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt    2019-03-14 02:46:16 UTC (rev 242932)
</span><span class="lines">@@ -129,6 +129,7 @@
</span><span class="cx">     ${TESTWEBKITAPI_DIR}/Tests/WTF/HashSet.cpp
</span><span class="cx">     ${TESTWEBKITAPI_DIR}/Tests/WTF/Hasher.cpp
</span><span class="cx">     ${TESTWEBKITAPI_DIR}/Tests/WTF/IntegerToStringConversion.cpp
</span><ins>+    ${TESTWEBKITAPI_DIR}/Tests/WTF/IteratorRange.cpp
</ins><span class="cx">     ${TESTWEBKITAPI_DIR}/Tests/WTF/JSONValue.cpp
</span><span class="cx">     ${TESTWEBKITAPI_DIR}/Tests/WTF/LEBDecoder.cpp
</span><span class="cx">     ${TESTWEBKITAPI_DIR}/Tests/WTF/LifecycleLogger.cpp
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (242931 => 242932)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2019-03-14 01:42:12 UTC (rev 242931)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj   2019-03-14 02:46:16 UTC (rev 242932)
</span><span class="lines">@@ -607,6 +607,7 @@
</span><span class="cx">          7CCE7F2E1A411B1000447C4C /* WKBrowsingContextGroupTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC3C4C7D14587AA60025FB62 /* WKBrowsingContextGroupTest.mm */; };
</span><span class="cx">          7CCE7F2F1A411B1000447C4C /* WKBrowsingContextLoadDelegateTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC3C4C7014575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm */; };
</span><span class="cx">          7CD4C26E1E2C0E6E00929470 /* StringConcatenate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CD4C26C1E2C0E6E00929470 /* StringConcatenate.cpp */; };
</span><ins>+               7CEB62AB223609DE0069CBB0 /* IteratorRange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CEB62A92236086C0069CBB0 /* IteratorRange.cpp */; };
</ins><span class="cx">           7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */; };
</span><span class="cx">          7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
</span><span class="cx">          830F2E0C209A6A8E00D36FF1 /* WebContentProcessDidTerminate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 830F2E0B209A6A7400D36FF1 /* WebContentProcessDidTerminate.mm */; };
</span><span class="lines">@@ -1820,6 +1821,7 @@
</span><span class="cx">          7CCE7EA31A4115CB00447C4C /* TestWebKitAPILibrary.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = TestWebKitAPILibrary.xcconfig; sourceTree = "<group>"; };
</span><span class="cx">          7CD0D5AA1D5534DE000CC9E1 /* Variant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Variant.cpp; sourceTree = "<group>"; };
</span><span class="cx">          7CD4C26C1E2C0E6E00929470 /* StringConcatenate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringConcatenate.cpp; sourceTree = "<group>"; };
</span><ins>+               7CEB62A92236086C0069CBB0 /* IteratorRange.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = IteratorRange.cpp; sourceTree = "<group>"; };
</ins><span class="cx">           7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKUserContentExtensionStore.mm; sourceTree = "<group>"; };
</span><span class="cx">          7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = "<group>"; };
</span><span class="cx">          7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -3246,6 +3248,7 @@
</span><span class="cx">                          0BCD833414857CE400EA2003 /* HashMap.cpp */,
</span><span class="cx">                          26B2DFF815BDE599004F691D /* HashSet.cpp */,
</span><span class="cx">                          266FAFD215E5775200F61D5B /* IntegerToStringConversion.cpp */,
</span><ins>+                               7CEB62A92236086C0069CBB0 /* IteratorRange.cpp */,
</ins><span class="cx">                           7A0509401FB9F04400B33FB8 /* JSONValue.cpp */,
</span><span class="cx">                          531C1D8D1DF8EF72006E979F /* LEBDecoder.cpp */,
</span><span class="cx">                          A57D54F71F3397B400A97AA7 /* LifecycleLogger.cpp */,
</span><span class="lines">@@ -3858,6 +3861,7 @@
</span><span class="cx">                          7C83DED21D0A590C00FEBCF3 /* HashMap.cpp in Sources */,
</span><span class="cx">                          7C83DED41D0A590C00FEBCF3 /* HashSet.cpp in Sources */,
</span><span class="cx">                          7C83DEE01D0A590C00FEBCF3 /* IntegerToStringConversion.cpp in Sources */,
</span><ins>+                               7CEB62AB223609DE0069CBB0 /* IteratorRange.cpp in Sources */,
</ins><span class="cx">                           7A0509411FB9F06400B33FB8 /* JSONValue.cpp in Sources */,
</span><span class="cx">                          531C1D8E1DF8EF72006E979F /* LEBDecoder.cpp in Sources */,
</span><span class="cx">                          A57D54F91F3397B400A97AA7 /* LifecycleLogger.cpp in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFIteratorRangecpp"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WTF/IteratorRange.cpp (0 => 242932)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/IteratorRange.cpp                            (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/IteratorRange.cpp       2019-03-14 02:46:16 UTC (rev 242932)
</span><span class="lines">@@ -0,0 +1,72 @@
</span><ins>+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include <array>
+#include <wtf/IteratorRange.h>
+#include <wtf/Vector.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTF_IteratorRange, MakeReversedRange)
+{
+    Vector<int> intVector { 10, 11, 12, 13 };
+
+    auto reversedRange = WTF::makeReversedRange(intVector);
+
+    static_assert(std::is_same<decltype(reversedRange.begin()), typename Vector<int>::reverse_iterator>::value, "IteratorRange has correct begin() iterator type");
+    static_assert(std::is_same<decltype(reversedRange.end()), typename Vector<int>::reverse_iterator>::value, "IteratorRange has correct end() iterator type");
+
+    EXPECT_EQ(reversedRange.begin(), intVector.rbegin());
+    EXPECT_EQ(reversedRange.end(), intVector.rend());
+
+    std::array<int, 4> expectedResults { { 13, 12, 11, 10 } };
+    size_t index = 0;
+
+    for (auto& value : reversedRange)
+        EXPECT_EQ(value, expectedResults[index++]);
+}
+
+TEST(WTF_IteratorRange, MakeConstReversedRange)
+{
+    const Vector<int> intVector { 10, 11, 12, 13 };
+
+    auto reversedRange = WTF::makeReversedRange(intVector);
+
+    static_assert(std::is_same<decltype(reversedRange.begin()), typename Vector<int>::const_reverse_iterator>::value, "IteratorRange has correct begin() iterator type");
+    static_assert(std::is_same<decltype(reversedRange.end()), typename Vector<int>::const_reverse_iterator>::value, "IteratorRange has correct end() iterator type");
+
+    EXPECT_EQ(reversedRange.begin(), intVector.rbegin());
+    EXPECT_EQ(reversedRange.end(), intVector.rend());
+
+    std::array<int, 4> expectedResults { { 13, 12, 11, 10 } };
+    size_t index = 0;
+
+    for (auto& value : reversedRange)
+        EXPECT_EQ(value, expectedResults[index++]);
+}
+
+} // namespace TestWebKitAPI
</ins></span></pre>
</div>
</div>

</body>
</html>