make-some-of-blink-custom-iterators-STL-compatible.patch 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. From d3cabbc7321d349a9bffda482df5afc0d4df1ac2 Mon Sep 17 00:00:00 2001
  2. From: Piotr Tworek <ptworek@vewd.com>
  3. Date: Thu, 30 Apr 2020 21:33:47 +0000
  4. Subject: [PATCH] Make some of blink custom iterators STL compatible.
  5. Blink has recently started using functions like std::any_of with some of
  6. the custom iterators it provides. On Linux this works in the default
  7. setup using libcxx, but fails with even the most recent versions of
  8. libstdc++. In all cases the error message (text in bug report) complains
  9. about lack of matching std::__iterator_category definition.
  10. From what I understand the error message is basically saying those
  11. iterators are not STL compatible due to missing traits as described
  12. in https://en.cppreference.com/w/cpp/iterator/iterator_traits. Such
  13. traits are provided by custom iterators defined in //base, or //cc.
  14. This patch adds the necessary traits to iterators that are currently
  15. affected by this problem.
  16. Bug: 1076869
  17. Change-Id: I9950a7100c32499ba96647317fa70b87dc22eaf9
  18. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2174199
  19. Reviewed-by: Kentaro Hara <haraken@chromium.org>
  20. Commit-Queue: Piotr Tworek <ptworek@vewd.com>
  21. Cr-Commit-Position: refs/heads/master@{#764426}
  22. ---
  23. .../core/layout/ng/ng_physical_container_fragment.h | 6 ++++++
  24. .../blink/renderer/platform/wtf/hash_iterators.h | 12 ++++++++++++
  25. third_party/blink/renderer/platform/wtf/hash_table.h | 6 ++++++
  26. 3 files changed, 24 insertions(+)
  27. 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
  28. index 1256e77c146..8b93107f2fc 100644
  29. --- a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
  30. +++ b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
  31. @@ -38,6 +38,12 @@ class CORE_EXPORT NGPhysicalContainerFragment : public NGPhysicalFragment {
  32. STACK_ALLOCATED();
  33. public:
  34. + using iterator_category = std::bidirectional_iterator_tag;
  35. + using value_type = NGLink;
  36. + using difference_type = ptrdiff_t;
  37. + using pointer = value_type*;
  38. + using reference = value_type&;
  39. +
  40. ConstIterator(const NGLink* current) : current_(current) {}
  41. const NGLink& operator*() const { return *PostLayoutOrCurrent(); }
  42. diff --git a/third_party/blink/renderer/platform/wtf/hash_iterators.h b/third_party/blink/renderer/platform/wtf/hash_iterators.h
  43. index f8e66e6be85..6003d02c509 100644
  44. --- a/third_party/blink/renderer/platform/wtf/hash_iterators.h
  45. +++ b/third_party/blink/renderer/platform/wtf/hash_iterators.h
  46. @@ -53,6 +53,12 @@ struct HashTableConstIteratorAdapter<HashTableType,
  47. typedef HashTableConstValuesIterator<HashTableType, KeyType, MappedType>
  48. ValuesIterator;
  49. + using iterator_category = std::bidirectional_iterator_tag;
  50. + using value_type = HashTableType;
  51. + using difference_type = ptrdiff_t;
  52. + using pointer = value_type*;
  53. + using reference = value_type&;
  54. +
  55. HashTableConstIteratorAdapter() = default;
  56. HashTableConstIteratorAdapter(
  57. const typename HashTableType::const_iterator& impl)
  58. @@ -94,6 +100,12 @@ struct HashTableIteratorAdapter<HashTableType,
  59. typedef HashTableValuesIterator<HashTableType, KeyType, MappedType>
  60. ValuesIterator;
  61. + using iterator_category = std::bidirectional_iterator_tag;
  62. + using value_type = HashTableType;
  63. + using difference_type = ptrdiff_t;
  64. + using pointer = value_type*;
  65. + using reference = value_type&;
  66. +
  67. HashTableIteratorAdapter() = default;
  68. HashTableIteratorAdapter(const typename HashTableType::iterator& impl)
  69. : impl_(impl) {}
  70. diff --git a/third_party/blink/renderer/platform/wtf/hash_table.h b/third_party/blink/renderer/platform/wtf/hash_table.h
  71. index f596fb5d41e..5a4468d6bd1 100644
  72. --- a/third_party/blink/renderer/platform/wtf/hash_table.h
  73. +++ b/third_party/blink/renderer/platform/wtf/hash_table.h
  74. @@ -2204,6 +2204,12 @@ struct HashTableConstIteratorAdapter {
  75. STACK_ALLOCATED();
  76. public:
  77. + using iterator_category = std::bidirectional_iterator_tag;
  78. + using value_type = HashTableType;
  79. + using difference_type = ptrdiff_t;
  80. + using pointer = value_type*;
  81. + using reference = value_type&;
  82. +
  83. HashTableConstIteratorAdapter() = default;
  84. HashTableConstIteratorAdapter(
  85. const typename HashTableType::const_iterator& impl)