# HG changeset patch
# User David Torres Sanchez <d.torressanchez@lancaster.ac.uk>
# Date 1637826358 -3600
# Thu Nov 25 08:45:58 2021 +0100
# Node ID 93c983122692826b48d3a40bc40100c8a4ea7650
# Parent a278d16bd2d082aa3c52ff4a9b0e2224ddc0549a
Fix C++20 compatibility issue (#631)
diff --git a/lemon/bits/array_map.h b/lemon/bits/array_map.h
a
|
b
|
|
75 | 75 | typedef typename Notifier::ObserverBase Parent; |
76 | 76 | |
77 | 77 | typedef std::allocator<Value> Allocator; |
| 78 | typedef std::allocator_traits<std::allocator<Value>> AllocatorTraits; |
78 | 79 | |
79 | 80 | public: |
80 | 81 | |
… |
… |
|
87 | 88 | Notifier* nf = Parent::notifier(); |
88 | 89 | Item it; |
89 | 90 | for (nf->first(it); it != INVALID; nf->next(it)) { |
90 | | int id = nf->id(it);; |
91 | | allocator.construct(&(values[id]), Value()); |
| 91 | int id = nf->id(it); |
| 92 | AllocatorTraits::construct(allocator, &(values[id]), Value()); |
92 | 93 | } |
93 | 94 | } |
94 | 95 | |
… |
… |
|
101 | 102 | Notifier* nf = Parent::notifier(); |
102 | 103 | Item it; |
103 | 104 | for (nf->first(it); it != INVALID; nf->next(it)) { |
104 | | int id = nf->id(it);; |
105 | | allocator.construct(&(values[id]), value); |
| 105 | int id = nf->id(it); |
| 106 | AllocatorTraits::construct(allocator, &(values[id]), value); |
106 | 107 | } |
107 | 108 | } |
108 | 109 | |
… |
… |
|
120 | 121 | Notifier* nf = Parent::notifier(); |
121 | 122 | Item it; |
122 | 123 | for (nf->first(it); it != INVALID; nf->next(it)) { |
123 | | int id = nf->id(it);; |
124 | | allocator.construct(&(values[id]), copy.values[id]); |
| 124 | int id = nf->id(it); |
| 125 | AllocatorTraits::construct(allocator, &(values[id]), copy.values[id]); |
125 | 126 | } |
126 | 127 | } |
127 | 128 | |
… |
… |
|
216 | 217 | Value* new_values = allocator.allocate(new_capacity); |
217 | 218 | Item it; |
218 | 219 | for (nf->first(it); it != INVALID; nf->next(it)) { |
219 | | int jd = nf->id(it);; |
| 220 | int jd = nf->id(it); |
220 | 221 | if (id != jd) { |
221 | | allocator.construct(&(new_values[jd]), values[jd]); |
222 | | allocator.destroy(&(values[jd])); |
| 222 | AllocatorTraits::construct(allocator, &(new_values[jd]), values[jd]); |
| 223 | AllocatorTraits::destroy(allocator, &(values[jd])); |
223 | 224 | } |
224 | 225 | } |
225 | 226 | if (capacity != 0) allocator.deallocate(values, capacity); |
226 | 227 | values = new_values; |
227 | 228 | capacity = new_capacity; |
228 | 229 | } |
229 | | allocator.construct(&(values[id]), Value()); |
| 230 | AllocatorTraits::construct(allocator, &(values[id]), Value()); |
230 | 231 | } |
231 | 232 | |
232 | 233 | // \brief Adds more new keys to the map. |
… |
… |
|
260 | 261 | } |
261 | 262 | } |
262 | 263 | if (found) continue; |
263 | | allocator.construct(&(new_values[id]), values[id]); |
264 | | allocator.destroy(&(values[id])); |
| 264 | AllocatorTraits::construct(allocator, &(new_values[id]), values[id]); |
| 265 | AllocatorTraits::destroy(allocator, &(values[id])); |
265 | 266 | } |
266 | 267 | if (capacity != 0) allocator.deallocate(values, capacity); |
267 | 268 | values = new_values; |
… |
… |
|
269 | 270 | } |
270 | 271 | for (int i = 0; i < int(keys.size()); ++i) { |
271 | 272 | int id = nf->id(keys[i]); |
272 | | allocator.construct(&(values[id]), Value()); |
| 273 | AllocatorTraits::construct(allocator, &(values[id]), Value()); |
273 | 274 | } |
274 | 275 | } |
275 | 276 | |
… |
… |
|
279 | 280 | // and it overrides the erase() member function of the observer base. |
280 | 281 | virtual void erase(const Key& key) { |
281 | 282 | int id = Parent::notifier()->id(key); |
282 | | allocator.destroy(&(values[id])); |
| 283 | AllocatorTraits::destroy(allocator, &(values[id])); |
283 | 284 | } |
284 | 285 | |
285 | 286 | // \brief Erase more keys from the map. |
… |
… |
|
289 | 290 | virtual void erase(const std::vector<Key>& keys) { |
290 | 291 | for (int i = 0; i < int(keys.size()); ++i) { |
291 | 292 | int id = Parent::notifier()->id(keys[i]); |
292 | | allocator.destroy(&(values[id])); |
| 293 | AllocatorTraits::destroy(allocator, &(values[id])); |
293 | 294 | } |
294 | 295 | } |
295 | 296 | |
… |
… |
|
302 | 303 | allocate_memory(); |
303 | 304 | Item it; |
304 | 305 | for (nf->first(it); it != INVALID; nf->next(it)) { |
305 | | int id = nf->id(it);; |
306 | | allocator.construct(&(values[id]), Value()); |
| 306 | int id = nf->id(it); |
| 307 | AllocatorTraits::construct(allocator, &(values[id]), Value()); |
307 | 308 | } |
308 | 309 | } |
309 | 310 | |
… |
… |
|
317 | 318 | Item it; |
318 | 319 | for (nf->first(it); it != INVALID; nf->next(it)) { |
319 | 320 | int id = nf->id(it); |
320 | | allocator.destroy(&(values[id])); |
| 321 | AllocatorTraits::destroy(allocator, &(values[id])); |
321 | 322 | } |
322 | 323 | allocator.deallocate(values, capacity); |
323 | 324 | capacity = 0; |
diff --git a/lemon/path.h b/lemon/path.h
a
|
b
|
|
448 | 448 | data.resize(len); |
449 | 449 | int index = 0; |
450 | 450 | for (typename CPath::ArcIt it(path); it != INVALID; ++it) { |
451 | | data[index] = it;; |
| 451 | data[index] = it; |
452 | 452 | ++index; |
453 | 453 | } |
454 | 454 | } |
… |
… |
|
460 | 460 | int index = len; |
461 | 461 | for (typename CPath::RevArcIt it(path); it != INVALID; ++it) { |
462 | 462 | --index; |
463 | | data[index] = it;; |
| 463 | data[index] = it; |
464 | 464 | } |
465 | 465 | } |
466 | 466 | |
… |
… |
|
503 | 503 | |
504 | 504 | Node *first, *last; |
505 | 505 | |
506 | | std::allocator<Node> alloc; |
| 506 | private: |
| 507 | typedef std::allocator<Node> Allocator; |
| 508 | typedef std::allocator_traits<std::allocator<Node>> AllocatorTraits; |
507 | 509 | |
508 | 510 | public: |
509 | 511 | |
… |
… |
|
663 | 665 | void clear() { |
664 | 666 | while (first != 0) { |
665 | 667 | last = first->next; |
666 | | alloc.destroy(first); |
667 | | alloc.deallocate(first, 1); |
| 668 | AllocatorTraits::destroy(_allocator, first); |
| 669 | _allocator.deallocate(first, 1); |
668 | 670 | first = last; |
669 | 671 | } |
670 | 672 | } |
… |
… |
|
676 | 678 | |
677 | 679 | /// \brief Add a new arc before the current path |
678 | 680 | void addFront(const Arc& arc) { |
679 | | Node *node = alloc.allocate(1); |
680 | | alloc.construct(node, Node()); |
| 681 | Node *node = _allocator.allocate(1); |
| 682 | AllocatorTraits::construct(_allocator, node, Node()); |
681 | 683 | node->prev = 0; |
682 | 684 | node->next = first; |
683 | 685 | node->arc = arc; |
… |
… |
|
698 | 700 | } else { |
699 | 701 | last = 0; |
700 | 702 | } |
701 | | alloc.destroy(node); |
702 | | alloc.deallocate(node, 1); |
| 703 | AllocatorTraits::destroy(_allocator, node); |
| 704 | _allocator.deallocate(node, 1); |
703 | 705 | } |
704 | 706 | |
705 | 707 | /// \brief The last arc of the path. |
… |
… |
|
709 | 711 | |
710 | 712 | /// \brief Add a new arc behind the current path. |
711 | 713 | void addBack(const Arc& arc) { |
712 | | Node *node = alloc.allocate(1); |
713 | | alloc.construct(node, Node()); |
| 714 | Node *node = _allocator.allocate(1); |
| 715 | AllocatorTraits::construct(_allocator, node, Node()); |
714 | 716 | node->next = 0; |
715 | 717 | node->prev = last; |
716 | 718 | node->arc = arc; |
… |
… |
|
731 | 733 | } else { |
732 | 734 | first = 0; |
733 | 735 | } |
734 | | alloc.destroy(node); |
735 | | alloc.deallocate(node, 1); |
| 736 | AllocatorTraits::destroy(_allocator, node); |
| 737 | _allocator.deallocate(node, 1); |
736 | 738 | } |
737 | 739 | |
738 | 740 | /// \brief Splice a path to the back of the current path. |
… |
… |
|
847 | 849 | } |
848 | 850 | } |
849 | 851 | |
| 852 | private: |
| 853 | Allocator _allocator; |
| 854 | |
850 | 855 | }; |
851 | 856 | |
852 | 857 | /// \brief A structure for representing directed paths in a digraph. |
… |
… |
|
875 | 880 | /// \brief Default constructor |
876 | 881 | /// |
877 | 882 | /// Default constructor |
878 | | StaticPath() : len(0), _arcs(0) {} |
| 883 | StaticPath() : _len(0), _arcs(0) {} |
879 | 884 | |
880 | 885 | /// \brief Copy constructor |
881 | 886 | /// |
… |
… |
|
1003 | 1008 | } |
1004 | 1009 | |
1005 | 1010 | /// \brief The length of the path. |
1006 | | int length() const { return len; } |
| 1011 | int length() const { return _len; } |
1007 | 1012 | |
1008 | 1013 | /// \brief Return true when the path is empty. |
1009 | | int empty() const { return len == 0; } |
| 1014 | int empty() const { return _len == 0; } |
1010 | 1015 | |
1011 | 1016 | /// \brief Reset the path to an empty one. |
1012 | 1017 | void clear() { |
1013 | | len = 0; |
| 1018 | _len = 0; |
1014 | 1019 | if (_arcs) delete[] _arcs; |
1015 | 1020 | _arcs = 0; |
1016 | 1021 | } |
… |
… |
|
1022 | 1027 | |
1023 | 1028 | /// \brief The last arc of the path. |
1024 | 1029 | const Arc& back() const { |
1025 | | return _arcs[len - 1]; |
| 1030 | return _arcs[_len - 1]; |
1026 | 1031 | } |
1027 | 1032 | |
1028 | 1033 | |
… |
… |
|
1030 | 1035 | |
1031 | 1036 | template <typename CPath> |
1032 | 1037 | void build(const CPath& path) { |
1033 | | len = path.length(); |
1034 | | _arcs = new Arc[len]; |
| 1038 | _len = path.length(); |
| 1039 | _arcs = new Arc[_len]; |
1035 | 1040 | int index = 0; |
1036 | 1041 | for (typename CPath::ArcIt it(path); it != INVALID; ++it) { |
1037 | 1042 | _arcs[index] = it; |
… |
… |
|
1041 | 1046 | |
1042 | 1047 | template <typename CPath> |
1043 | 1048 | void buildRev(const CPath& path) { |
1044 | | len = path.length(); |
1045 | | _arcs = new Arc[len]; |
1046 | | int index = len; |
| 1049 | _len = path.length(); |
| 1050 | _arcs = new Arc[_len]; |
| 1051 | int index = _len; |
1047 | 1052 | for (typename CPath::RevArcIt it(path); it != INVALID; ++it) { |
1048 | 1053 | --index; |
1049 | 1054 | _arcs[index] = it; |
… |
… |
|
1051 | 1056 | } |
1052 | 1057 | |
1053 | 1058 | private: |
1054 | | int len; |
| 1059 | int _len; |
1055 | 1060 | Arc* _arcs; |
1056 | 1061 | }; |
1057 | 1062 | |