|
| 1 | +This reverts commit https://github.com/chromium/chromium/commit/4f6cc657b0953fb353111d581c130858e90aec08 |
| 2 | + |
| 3 | +diff --git a/base/containers/buffer_iterator.h b/base/containers/buffer_iterator.h |
| 4 | +index 61abd79721..e2d9528a24 100644 |
| 5 | +--- a/base/containers/buffer_iterator.h |
| 6 | ++++ b/base/containers/buffer_iterator.h |
| 7 | +@@ -80,8 +80,8 @@ class BufferIterator { |
| 8 | + |
| 9 | + // Copies out an object. As compared to using `Object`, this avoids potential |
| 10 | + // unaligned access which may be undefined behavior. |
| 11 | +- template <typename T> |
| 12 | +- requires(std::is_trivially_copyable_v<T>) |
| 13 | ++ template <typename T, |
| 14 | ++ typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> |
| 15 | + std::optional<T> CopyObject() { |
| 16 | + std::optional<T> t; |
| 17 | + if (remaining_.size() >= sizeof(T)) { |
| 18 | +@@ -101,8 +101,8 @@ class BufferIterator { |
| 19 | + // `CopyObject` as it avoids this problem entirely. |
| 20 | + // TODO(danakj): We should probably CHECK this instead of allowing UB into |
| 21 | + // production. |
| 22 | +- template <typename T> |
| 23 | +- requires(std::is_trivially_copyable_v<T>) |
| 24 | ++ template <typename T, |
| 25 | ++ typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> |
| 26 | + const T* Object() { |
| 27 | + return MutableObject<const T>(); |
| 28 | + } |
| 29 | +@@ -117,8 +117,8 @@ class BufferIterator { |
| 30 | + // `CopyObject` as it avoids this problem entirely. |
| 31 | + // TODO(danakj): We should probably CHECK this instead of allowing UB into |
| 32 | + // production. |
| 33 | +- template <typename T> |
| 34 | +- requires(std::is_trivially_copyable_v<T>) |
| 35 | ++ template <typename T, |
| 36 | ++ typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> |
| 37 | + T* MutableObject() { |
| 38 | + T* t = nullptr; |
| 39 | + if (remaining_.size() >= sizeof(T)) { |
| 40 | +@@ -142,8 +142,8 @@ class BufferIterator { |
| 41 | + // using the span will cause Undefined Behaviour. |
| 42 | + // TODO(danakj): We should probably CHECK this instead of allowing UB into |
| 43 | + // production. |
| 44 | +- template <typename T> |
| 45 | +- requires(std::is_trivially_copyable_v<T>) |
| 46 | ++ template <typename T, |
| 47 | ++ typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> |
| 48 | + span<T> MutableSpan(size_t count) { |
| 49 | + size_t byte_size; |
| 50 | + if (!CheckMul(sizeof(T), count).AssignIfValid(&byte_size)) { |
| 51 | +@@ -165,9 +165,10 @@ class BufferIterator { |
| 52 | + |
| 53 | + // An overload for when the size is known at compile time. The result will be |
| 54 | + // a fixed-size span. |
| 55 | +- template <typename T, size_t N> |
| 56 | +- requires(N <= std::numeric_limits<size_t>::max() / sizeof(T) && |
| 57 | +- std::is_trivially_copyable_v<T>) |
| 58 | ++ template <typename T, |
| 59 | ++ size_t N, |
| 60 | ++ typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> |
| 61 | ++ requires(N <= std::numeric_limits<size_t>::max() / sizeof(T)) |
| 62 | + std::optional<span<T, N>> MutableSpan() { |
| 63 | + constexpr size_t byte_size = |
| 64 | + N * sizeof(T); // Overflow is checked by `requires`. |
| 65 | +@@ -193,17 +194,18 @@ class BufferIterator { |
| 66 | + // using the span will cause Undefined Behaviour. |
| 67 | + // TODO(danakj): We should probably CHECK this instead of allowing UB into |
| 68 | + // production. |
| 69 | +- template <typename T> |
| 70 | +- requires(std::is_trivially_copyable_v<T>) |
| 71 | ++ template <typename T, |
| 72 | ++ typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> |
| 73 | + span<const T> Span(size_t count) { |
| 74 | + return MutableSpan<const T>(count); |
| 75 | + } |
| 76 | + |
| 77 | + // An overload for when the size is known at compile time. The result will be |
| 78 | + // a fixed-size span. |
| 79 | +- template <typename T, size_t N> |
| 80 | +- requires(N <= std::numeric_limits<size_t>::max() / sizeof(T) && |
| 81 | +- std::is_trivially_copyable_v<T>) |
| 82 | ++ template <typename T, |
| 83 | ++ size_t N, |
| 84 | ++ typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> |
| 85 | ++ requires(N <= std::numeric_limits<size_t>::max() / sizeof(T)) |
| 86 | + std::optional<span<const T, N>> Span() { |
| 87 | + return MutableSpan<const T, N>(); |
| 88 | + } |
| 89 | +diff --git a/base/containers/flat_map.h b/base/containers/flat_map.h |
| 90 | +index 612e15f7ff..25158d4eb9 100644 |
| 91 | +--- a/base/containers/flat_map.h |
| 92 | ++++ b/base/containers/flat_map.h |
| 93 | +@@ -234,12 +234,13 @@ class flat_map : public ::base::internal:: |
| 94 | + iterator insert_or_assign(const_iterator hint, K&& key, M&& obj); |
| 95 | + |
| 96 | + template <class K, class... Args> |
| 97 | +- requires(std::is_constructible_v<key_type, K &&>) |
| 98 | +- std::pair<iterator, bool> try_emplace(K&& key, Args&&... args); |
| 99 | ++ std::enable_if_t<std::is_constructible_v<key_type, K&&>, |
| 100 | ++ std::pair<iterator, bool>> |
| 101 | ++ try_emplace(K&& key, Args&&... args); |
| 102 | + |
| 103 | + template <class K, class... Args> |
| 104 | +- requires(std::is_constructible_v<key_type, K &&>) |
| 105 | +- iterator try_emplace(const_iterator hint, K&& key, Args&&... args); |
| 106 | ++ std::enable_if_t<std::is_constructible_v<key_type, K&&>, iterator> |
| 107 | ++ try_emplace(const_iterator hint, K&& key, Args&&... args); |
| 108 | + |
| 109 | + // -------------------------------------------------------------------------- |
| 110 | + // General operations. |
| 111 | +@@ -324,12 +325,10 @@ auto flat_map<Key, Mapped, Compare, Container>::insert_or_assign( |
| 112 | + |
| 113 | + template <class Key, class Mapped, class Compare, class Container> |
| 114 | + template <class K, class... Args> |
| 115 | +- requires(std::is_constructible_v< |
| 116 | +- typename flat_map<Key, Mapped, Compare, Container>::key_type, |
| 117 | +- K &&>) |
| 118 | + auto flat_map<Key, Mapped, Compare, Container>::try_emplace(K&& key, |
| 119 | + Args&&... args) |
| 120 | +- -> std::pair<iterator, bool> { |
| 121 | ++ -> std::enable_if_t<std::is_constructible_v<key_type, K&&>, |
| 122 | ++ std::pair<iterator, bool>> { |
| 123 | + return tree::emplace_key_args( |
| 124 | + key, std::piecewise_construct, |
| 125 | + std::forward_as_tuple(std::forward<K>(key)), |
| 126 | +@@ -338,13 +337,10 @@ auto flat_map<Key, Mapped, Compare, Container>::try_emplace(K&& key, |
| 127 | + |
| 128 | + template <class Key, class Mapped, class Compare, class Container> |
| 129 | + template <class K, class... Args> |
| 130 | +- requires(std::is_constructible_v< |
| 131 | +- typename flat_map<Key, Mapped, Compare, Container>::key_type, |
| 132 | +- K &&>) |
| 133 | + auto flat_map<Key, Mapped, Compare, Container>::try_emplace(const_iterator hint, |
| 134 | + K&& key, |
| 135 | + Args&&... args) |
| 136 | +- -> iterator { |
| 137 | ++ -> std::enable_if_t<std::is_constructible_v<key_type, K&&>, iterator> { |
| 138 | + return tree::emplace_hint_key_args( |
| 139 | + hint, key, std::piecewise_construct, |
| 140 | + std::forward_as_tuple(std::forward<K>(key)), |
| 141 | +diff --git a/base/containers/intrusive_heap.h b/base/containers/intrusive_heap.h |
| 142 | +index d0a60ed748..70ecf19d91 100644 |
| 143 | +--- a/base/containers/intrusive_heap.h |
| 144 | ++++ b/base/containers/intrusive_heap.h |
| 145 | +@@ -572,8 +572,7 @@ class IntrusiveHeap { |
| 146 | + private: |
| 147 | + // Templated version of ToIndex that lets insert/erase/Replace work with all |
| 148 | + // integral types. |
| 149 | +- template <typename I> |
| 150 | +- requires(std::is_integral_v<I>) |
| 151 | ++ template <typename I, typename = std::enable_if_t<std::is_integral_v<I>>> |
| 152 | + size_type ToIndex(I pos) { |
| 153 | + return static_cast<size_type>(pos); |
| 154 | + } |
0 commit comments