summaryrefslogtreecommitdiff
path: root/dev-cpp/sparsehash/files/sparsehash-2.0.4-c++20.patch
blob: 776443d68c5ef3479b07bcfd163def48ad843ef5 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
https://github.com/igorsugak/sparsehash/commit/6940fcaba9766735e48064b930690d67fc2f84ea
https://github.com/sparsehash/sparsehash/pull/165
https://bugs.gentoo.org/967004
C++20 removed many deprecated std::allocator members, causing sparsehash
to fail when it is built with -std=c++20. This implements most of
the uses of the removed members in terms of std::allocator_traits.

There are no corresponding reference and const_reference members
in std::allocator_traits, in which case used the actual
value_type&/const value_type& instead.
From 6940fcaba9766735e48064b930690d67fc2f84ea Mon Sep 17 00:00:00 2001
From: sugak <sugak@fb.com>
Date: Mon, 29 Nov 2021 18:01:19 -0800
Subject: [PATCH] fix build with -std=c++20

---
 src/sparsehash/internal/densehashtable.h  | 46 ++++++++++++---------
 src/sparsehash/internal/sparsehashtable.h | 50 +++++++++++++----------
 src/sparsehash/sparsetable                | 37 +++++++++--------
 3 files changed, 74 insertions(+), 59 deletions(-)

diff --git a/src/sparsehash/internal/densehashtable.h b/src/sparsehash/internal/densehashtable.h
index cdf4ff6..79cecab 100644
--- a/src/sparsehash/internal/densehashtable.h
+++ b/src/sparsehash/internal/densehashtable.h
@@ -149,7 +149,8 @@ struct dense_hashtable_const_iterator;
 template <class V, class K, class HF, class ExK, class SetK, class EqK, class A>
 struct dense_hashtable_iterator {
  private:
-  typedef typename A::template rebind<V>::other value_alloc_type;
+  typedef typename std::allocator_traits<A>::template rebind_alloc<V> value_alloc_type;
+  typedef std::allocator_traits<value_alloc_type> value_alloc_traits;
 
  public:
   typedef dense_hashtable_iterator<V,K,HF,ExK,SetK,EqK,A>       iterator;
@@ -157,10 +158,10 @@ struct dense_hashtable_iterator {
 
   typedef std::forward_iterator_tag iterator_category;  // very little defined!
   typedef V value_type;
-  typedef typename value_alloc_type::difference_type difference_type;
-  typedef typename value_alloc_type::size_type size_type;
-  typedef typename value_alloc_type::reference reference;
-  typedef typename value_alloc_type::pointer pointer;
+  typedef typename value_alloc_traits::difference_type difference_type;
+  typedef typename value_alloc_traits::size_type size_type;
+  typedef value_type& reference;
+  typedef typename value_alloc_traits::pointer pointer;
 
   // "Real" constructor and default constructor
   dense_hashtable_iterator(const dense_hashtable<V,K,HF,ExK,SetK,EqK,A> *h,
@@ -202,7 +203,8 @@ struct dense_hashtable_iterator {
 template <class V, class K, class HF, class ExK, class SetK, class EqK, class A>
 struct dense_hashtable_const_iterator {
  private:
-  typedef typename A::template rebind<V>::other value_alloc_type;
+  typedef typename std::allocator_traits<A>::template rebind_alloc<V> value_alloc_type;
+  typedef std::allocator_traits<value_alloc_type> value_alloc_traits;
 
  public:
   typedef dense_hashtable_iterator<V,K,HF,ExK,SetK,EqK,A>       iterator;
@@ -210,10 +212,10 @@ struct dense_hashtable_const_iterator {
 
   typedef std::forward_iterator_tag iterator_category;  // very little defined!
   typedef V value_type;
-  typedef typename value_alloc_type::difference_type difference_type;
-  typedef typename value_alloc_type::size_type size_type;
-  typedef typename value_alloc_type::const_reference reference;
-  typedef typename value_alloc_type::const_pointer pointer;
+  typedef typename value_alloc_traits::difference_type difference_type;
+  typedef typename value_alloc_traits::size_type size_type;
+  typedef const value_type& reference;
+  typedef typename value_alloc_traits::const_pointer pointer;
 
   // "Real" constructor and default constructor
   dense_hashtable_const_iterator(
@@ -259,7 +261,8 @@ template <class Value, class Key, class HashFcn,
           class ExtractKey, class SetKey, class EqualKey, class Alloc>
 class dense_hashtable {
  private:
-  typedef typename Alloc::template rebind<Value>::other value_alloc_type;
+  typedef typename std::allocator_traits<Alloc>::template rebind_alloc<Value> value_alloc_type;
+  typedef std::allocator_traits<value_alloc_type> value_alloc_traits;
 
  public:
   typedef Key key_type;
@@ -268,12 +271,12 @@ class dense_hashtable {
   typedef EqualKey key_equal;
   typedef Alloc allocator_type;
 
-  typedef typename value_alloc_type::size_type size_type;
-  typedef typename value_alloc_type::difference_type difference_type;
-  typedef typename value_alloc_type::reference reference;
-  typedef typename value_alloc_type::const_reference const_reference;
-  typedef typename value_alloc_type::pointer pointer;
-  typedef typename value_alloc_type::const_pointer const_pointer;
+  typedef typename value_alloc_traits::size_type size_type;
+  typedef typename value_alloc_traits::difference_type difference_type;
+  typedef value_type& reference;
+  typedef const value_type& const_reference;
+  typedef typename value_alloc_traits::pointer pointer;
+  typedef typename value_alloc_traits::const_pointer const_pointer;
   typedef dense_hashtable_iterator<Value, Key, HashFcn,
                                    ExtractKey, SetKey, EqualKey, Alloc>
   iterator;
@@ -518,7 +521,9 @@ class dense_hashtable {
   // FUNCTIONS CONCERNING SIZE
  public:
   size_type size() const      { return num_elements - num_deleted; }
-  size_type max_size() const  { return val_info.max_size(); }
+  size_type max_size() const  {
+      return std::allocator_traits<ValInfo>::max_size(val_info);
+  }
   bool empty() const          { return size() == 0; }
   size_type bucket_count() const      { return num_buckets; }
   size_type max_bucket_count() const  { return max_size(); }
@@ -1170,8 +1175,9 @@ class dense_hashtable {
   template <class A>
   class alloc_impl : public A {
    public:
-    typedef typename A::pointer pointer;
-    typedef typename A::size_type size_type;
+    typedef std::allocator_traits<A> alloc_traits;
+    typedef typename alloc_traits::pointer pointer;
+    typedef typename alloc_traits::size_type size_type;
 
     // Convert a normal allocator to one that has realloc_or_die()
     alloc_impl(const A& a) : A(a) { }
diff --git a/src/sparsehash/internal/sparsehashtable.h b/src/sparsehash/internal/sparsehashtable.h
index f54ea51..1c71d6d 100644
--- a/src/sparsehash/internal/sparsehashtable.h
+++ b/src/sparsehash/internal/sparsehashtable.h
@@ -160,7 +160,8 @@ struct sparse_hashtable_const_iterator;
 template <class V, class K, class HF, class ExK, class SetK, class EqK, class A>
 struct sparse_hashtable_iterator {
  private:
-  typedef typename A::template rebind<V>::other value_alloc_type;
+  typedef typename std::allocator_traits<A>::template rebind_alloc<V> value_alloc_type;
+  typedef std::allocator_traits<value_alloc_type> value_alloc_traits;
 
  public:
   typedef sparse_hashtable_iterator<V,K,HF,ExK,SetK,EqK,A>       iterator;
@@ -170,10 +171,10 @@ struct sparse_hashtable_iterator {
 
   typedef std::forward_iterator_tag iterator_category;  // very little defined!
   typedef V value_type;
-  typedef typename value_alloc_type::difference_type difference_type;
-  typedef typename value_alloc_type::size_type size_type;
-  typedef typename value_alloc_type::reference reference;
-  typedef typename value_alloc_type::pointer pointer;
+  typedef typename value_alloc_traits::difference_type difference_type;
+  typedef typename value_alloc_traits::size_type size_type;
+  typedef value_type& reference;
+  typedef typename value_alloc_traits::pointer pointer;
 
   // "Real" constructor and default constructor
   sparse_hashtable_iterator(const sparse_hashtable<V,K,HF,ExK,SetK,EqK,A> *h,
@@ -212,7 +213,9 @@ struct sparse_hashtable_iterator {
 template <class V, class K, class HF, class ExK, class SetK, class EqK, class A>
 struct sparse_hashtable_const_iterator {
  private:
-  typedef typename A::template rebind<V>::other value_alloc_type;
+  typedef typename std::allocator_traits<A>::template rebind_alloc<V> value_alloc_type;
+  typedef typename std::allocator_traits<value_alloc_type> value_alloc_traits;
+
 
  public:
   typedef sparse_hashtable_iterator<V,K,HF,ExK,SetK,EqK,A>       iterator;
@@ -222,10 +225,10 @@ struct sparse_hashtable_const_iterator {
 
   typedef std::forward_iterator_tag iterator_category;  // very little defined!
   typedef V value_type;
-  typedef typename value_alloc_type::difference_type difference_type;
-  typedef typename value_alloc_type::size_type size_type;
-  typedef typename value_alloc_type::const_reference reference;
-  typedef typename value_alloc_type::const_pointer pointer;
+  typedef typename value_alloc_traits::difference_type difference_type;
+  typedef typename value_alloc_traits::size_type size_type;
+  typedef const value_type& reference;
+  typedef typename value_alloc_traits::const_pointer pointer;
 
   // "Real" constructor and default constructor
   sparse_hashtable_const_iterator(const sparse_hashtable<V,K,HF,ExK,SetK,EqK,A> *h,
@@ -267,7 +270,9 @@ struct sparse_hashtable_const_iterator {
 template <class V, class K, class HF, class ExK, class SetK, class EqK, class A>
 struct sparse_hashtable_destructive_iterator {
  private:
-  typedef typename A::template rebind<V>::other value_alloc_type;
+  typedef typename std::allocator_traits<A>::template rebind_alloc<V> value_alloc_type;
+  typedef std::allocator_traits<value_alloc_type> value_alloc_traits;
+
 
  public:
   typedef sparse_hashtable_destructive_iterator<V,K,HF,ExK,SetK,EqK,A> iterator;
@@ -276,10 +281,10 @@ struct sparse_hashtable_destructive_iterator {
 
   typedef std::forward_iterator_tag iterator_category;  // very little defined!
   typedef V value_type;
-  typedef typename value_alloc_type::difference_type difference_type;
-  typedef typename value_alloc_type::size_type size_type;
-  typedef typename value_alloc_type::reference reference;
-  typedef typename value_alloc_type::pointer pointer;
+  typedef typename value_alloc_traits::difference_type difference_type;
+  typedef typename value_alloc_traits::size_type size_type;
+  typedef value_type& reference;
+  typedef typename value_alloc_traits::pointer pointer;
 
   // "Real" constructor and default constructor
   sparse_hashtable_destructive_iterator(const
@@ -320,7 +325,8 @@ template <class Value, class Key, class HashFcn,
           class ExtractKey, class SetKey, class EqualKey, class Alloc>
 class sparse_hashtable {
  private:
-  typedef typename Alloc::template rebind<Value>::other value_alloc_type;
+  typedef typename std::allocator_traits<Alloc>::template rebind_alloc<Value> value_alloc_type;
+  typedef std::allocator_traits<value_alloc_type> value_alloc_traits;
 
  public:
   typedef Key key_type;
@@ -329,12 +335,12 @@ class sparse_hashtable {
   typedef EqualKey key_equal;
   typedef Alloc allocator_type;
 
-  typedef typename value_alloc_type::size_type size_type;
-  typedef typename value_alloc_type::difference_type difference_type;
-  typedef typename value_alloc_type::reference reference;
-  typedef typename value_alloc_type::const_reference const_reference;
-  typedef typename value_alloc_type::pointer pointer;
-  typedef typename value_alloc_type::const_pointer const_pointer;
+  typedef typename value_alloc_traits::size_type size_type;
+  typedef typename value_alloc_traits::difference_type difference_type;
+  typedef value_type& reference;
+  typedef const value_type& const_reference;
+  typedef typename value_alloc_traits::pointer pointer;
+  typedef typename value_alloc_traits::const_pointer const_pointer;
   typedef sparse_hashtable_iterator<Value, Key, HashFcn, ExtractKey,
                                     SetKey, EqualKey, Alloc>
   iterator;
diff --git a/src/sparsehash/sparsetable b/src/sparsehash/sparsetable
index 6259ebd..60c71dc 100644
--- a/src/sparsehash/sparsetable
+++ b/src/sparsehash/sparsetable
@@ -802,16 +802,17 @@ class destructive_two_d_iterator {
 template <class T, u_int16_t GROUP_SIZE, class Alloc>
 class sparsegroup {
  private:
-  typedef typename Alloc::template rebind<T>::other value_alloc_type;
+  typedef typename std::allocator_traits<Alloc>::template rebind_alloc<T> value_alloc_type;
+  typedef std::allocator_traits<value_alloc_type> value_alloc_traits;
 
  public:
   // Basic types
   typedef T value_type;
   typedef Alloc allocator_type;
-  typedef typename value_alloc_type::reference reference;
-  typedef typename value_alloc_type::const_reference const_reference;
-  typedef typename value_alloc_type::pointer pointer;
-  typedef typename value_alloc_type::const_pointer const_pointer;
+  typedef value_type& reference;
+  typedef const value_type& const_reference;
+  typedef typename value_alloc_traits::pointer pointer;
+  typedef typename value_alloc_traits::const_pointer const_pointer;
 
   typedef table_iterator<sparsegroup<T, GROUP_SIZE, Alloc> > iterator;
   typedef const_table_iterator<sparsegroup<T, GROUP_SIZE, Alloc> >
@@ -1289,8 +1290,9 @@ class sparsegroup {
   template <class A>
   class alloc_impl : public A {
    public:
-    typedef typename A::pointer pointer;
-    typedef typename A::size_type size_type;
+    typedef std::allocator_traits<A> alloc_traits;
+    typedef typename alloc_traits::pointer pointer;
+    typedef typename alloc_traits::size_type size_type;
 
     // Convert a normal allocator to one that has realloc_or_die()
     alloc_impl(const A& a) : A(a) { }
@@ -1362,20 +1364,21 @@ template <class T, u_int16_t GROUP_SIZE = DEFAULT_SPARSEGROUP_SIZE,
           class Alloc = libc_allocator_with_realloc<T> >
 class sparsetable {
  private:
-  typedef typename Alloc::template rebind<T>::other value_alloc_type;
-  typedef typename Alloc::template rebind<
-      sparsegroup<T, GROUP_SIZE, value_alloc_type> >::other vector_alloc;
+  typedef typename std::allocator_traits<Alloc>::template rebind_alloc<T> value_alloc_type;
+  typedef std::allocator_traits<value_alloc_type> value_alloc_traits;
+  typedef typename std::allocator_traits<Alloc>::template rebind_alloc<
+      sparsegroup<T, GROUP_SIZE, value_alloc_type> > vector_alloc;
 
  public:
   // Basic types
   typedef T value_type;                        // stolen from stl_vector.h
   typedef Alloc allocator_type;
-  typedef typename value_alloc_type::size_type size_type;
-  typedef typename value_alloc_type::difference_type difference_type;
-  typedef typename value_alloc_type::reference reference;
-  typedef typename value_alloc_type::const_reference const_reference;
-  typedef typename value_alloc_type::pointer pointer;
-  typedef typename value_alloc_type::const_pointer const_pointer;
+  typedef typename value_alloc_traits::size_type size_type;
+  typedef typename value_alloc_traits::difference_type difference_type;
+  typedef value_type& reference;
+  typedef const value_type& const_reference;
+  typedef typename value_alloc_traits::pointer pointer;
+  typedef typename value_alloc_traits::const_pointer const_pointer;
   typedef table_iterator<sparsetable<T, GROUP_SIZE, Alloc> > iterator;
   typedef const_table_iterator<sparsetable<T, GROUP_SIZE, Alloc> >
       const_iterator;
@@ -1446,7 +1449,7 @@ class sparsetable {
     return destructive_iterator(groups.begin(), groups.end(), groups.end());
   }
 
-  typedef sparsegroup<value_type, GROUP_SIZE, allocator_type> group_type;
+  typedef sparsegroup<value_type, GROUP_SIZE, value_alloc_type> group_type;
   typedef std::vector<group_type, vector_alloc > group_vector_type;
 
   typedef typename group_vector_type::reference GroupsReference;