summarylogtreecommitdiffstats
path: root/make-some-of-blink-custom-iterators-STL-compatible.patch
blob: 30cbdefcc65faec13640b93784e7ce3fde1b7a4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
From d3cabbc7321d349a9bffda482df5afc0d4df1ac2 Mon Sep 17 00:00:00 2001
From: Piotr Tworek <ptworek@vewd.com>
Date: Thu, 30 Apr 2020 21:33:47 +0000
Subject: [PATCH] Make some of blink custom iterators STL compatible.

Blink has recently started using functions like std::any_of with some of
the custom iterators it provides. On Linux this works in the default
setup using libcxx, but fails with even the most recent versions of
libstdc++. In all cases the error message (text in bug report) complains
about lack of matching std::__iterator_category definition.

From what I understand the error message is basically saying those
iterators are not STL compatible due to missing traits as described
in https://en.cppreference.com/w/cpp/iterator/iterator_traits. Such
traits are provided by custom iterators defined in //base, or //cc.

This patch adds the necessary traits to iterators that are currently
affected by this problem.

Bug: 1076869
Change-Id: I9950a7100c32499ba96647317fa70b87dc22eaf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2174199
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Piotr Tworek <ptworek@vewd.com>
Cr-Commit-Position: refs/heads/master@{#764426}
---
 .../core/layout/ng/ng_physical_container_fragment.h  |  6 ++++++
 .../blink/renderer/platform/wtf/hash_iterators.h     | 12 ++++++++++++
 third_party/blink/renderer/platform/wtf/hash_table.h |  6 ++++++
 3 files changed, 24 insertions(+)

diff --git a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
index 1256e77c146..8b93107f2fc 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
+++ b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
@@ -38,6 +38,12 @@ class CORE_EXPORT NGPhysicalContainerFragment : public NGPhysicalFragment {
       STACK_ALLOCATED();
 
      public:
+      using iterator_category = std::bidirectional_iterator_tag;
+      using value_type = NGLink;
+      using difference_type = ptrdiff_t;
+      using pointer = value_type*;
+      using reference = value_type&;
+
       ConstIterator(const NGLink* current) : current_(current) {}
 
       const NGLink& operator*() const { return *PostLayoutOrCurrent(); }
diff --git a/third_party/blink/renderer/platform/wtf/hash_iterators.h b/third_party/blink/renderer/platform/wtf/hash_iterators.h
index f8e66e6be85..6003d02c509 100644
--- a/third_party/blink/renderer/platform/wtf/hash_iterators.h
+++ b/third_party/blink/renderer/platform/wtf/hash_iterators.h
@@ -53,6 +53,12 @@ struct HashTableConstIteratorAdapter<HashTableType,
   typedef HashTableConstValuesIterator<HashTableType, KeyType, MappedType>
       ValuesIterator;
 
+  using iterator_category = std::bidirectional_iterator_tag;
+  using value_type = HashTableType;
+  using difference_type = ptrdiff_t;
+  using pointer = value_type*;
+  using reference = value_type&;
+
   HashTableConstIteratorAdapter() = default;
   HashTableConstIteratorAdapter(
       const typename HashTableType::const_iterator& impl)
@@ -94,6 +100,12 @@ struct HashTableIteratorAdapter<HashTableType,
   typedef HashTableValuesIterator<HashTableType, KeyType, MappedType>
       ValuesIterator;
 
+  using iterator_category = std::bidirectional_iterator_tag;
+  using value_type = HashTableType;
+  using difference_type = ptrdiff_t;
+  using pointer = value_type*;
+  using reference = value_type&;
+
   HashTableIteratorAdapter() = default;
   HashTableIteratorAdapter(const typename HashTableType::iterator& impl)
       : impl_(impl) {}
diff --git a/third_party/blink/renderer/platform/wtf/hash_table.h b/third_party/blink/renderer/platform/wtf/hash_table.h
index f596fb5d41e..5a4468d6bd1 100644
--- a/third_party/blink/renderer/platform/wtf/hash_table.h
+++ b/third_party/blink/renderer/platform/wtf/hash_table.h
@@ -2204,6 +2204,12 @@ struct HashTableConstIteratorAdapter {
   STACK_ALLOCATED();
 
  public:
+  using iterator_category = std::bidirectional_iterator_tag;
+  using value_type = HashTableType;
+  using difference_type = ptrdiff_t;
+  using pointer = value_type*;
+  using reference = value_type&;
+
   HashTableConstIteratorAdapter() = default;
   HashTableConstIteratorAdapter(
       const typename HashTableType::const_iterator& impl)