Skip to content

Commit

Permalink
Update for c++20
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Liberty <[email protected]>
  • Loading branch information
maliberty committed Nov 13, 2024
1 parent 62ac753 commit f871b10
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lemon/bits/array_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace lemon {
typedef typename Notifier::ObserverBase Parent;

typedef std::allocator<Value> Allocator;
typedef std::allocator_traits<Allocator> AllocatorTraits;

public:

Expand All @@ -88,7 +89,7 @@ namespace lemon {
Item it;
for (nf->first(it); it != INVALID; nf->next(it)) {
int id = nf->id(it);;
allocator.construct(&(values[id]), Value());
AllocatorTraits::construct(allocator, &(values[id]), Value());
}
}

Expand All @@ -102,7 +103,7 @@ namespace lemon {
Item it;
for (nf->first(it); it != INVALID; nf->next(it)) {
int id = nf->id(it);;
allocator.construct(&(values[id]), value);
AllocatorTraits::construct(allocator, &(values[id]), value);
}
}

Expand All @@ -121,7 +122,7 @@ namespace lemon {
Item it;
for (nf->first(it); it != INVALID; nf->next(it)) {
int id = nf->id(it);;
allocator.construct(&(values[id]), copy.values[id]);
AllocatorTraits::construct(allocator, &(values[id]), copy.values[id]);
}
}

Expand Down Expand Up @@ -218,15 +219,15 @@ namespace lemon {
for (nf->first(it); it != INVALID; nf->next(it)) {
int jd = nf->id(it);;
if (id != jd) {
allocator.construct(&(new_values[jd]), values[jd]);
allocator.destroy(&(values[jd]));
AllocatorTraits::construct(allocator, &(new_values[jd]), values[jd]);
AllocatorTraits::destroy(allocator, &(values[jd]));
}
}
if (capacity != 0) allocator.deallocate(values, capacity);
values = new_values;
capacity = new_capacity;
}
allocator.construct(&(values[id]), Value());
AllocatorTraits::construct(allocator, &(values[id]), Value());
}

// \brief Adds more new keys to the map.
Expand Down Expand Up @@ -260,16 +261,16 @@ namespace lemon {
}
}
if (found) continue;
allocator.construct(&(new_values[id]), values[id]);
allocator.destroy(&(values[id]));
AllocatorTraits::construct(allocator, &(new_values[id]), values[id]);
AllocatorTraits::destroy(allocator, &(values[id]));
}
if (capacity != 0) allocator.deallocate(values, capacity);
values = new_values;
capacity = new_capacity;
}
for (int i = 0; i < int(keys.size()); ++i) {
int id = nf->id(keys[i]);
allocator.construct(&(values[id]), Value());
AllocatorTraits::construct(allocator, &(values[id]), Value());
}
}

Expand All @@ -279,7 +280,7 @@ namespace lemon {
// and it overrides the erase() member function of the observer base.
virtual void erase(const Key& key) {
int id = Parent::notifier()->id(key);
allocator.destroy(&(values[id]));
AllocatorTraits::destroy(allocator, &(values[id]));
}

// \brief Erase more keys from the map.
Expand All @@ -289,7 +290,7 @@ namespace lemon {
virtual void erase(const std::vector<Key>& keys) {
for (int i = 0; i < int(keys.size()); ++i) {
int id = Parent::notifier()->id(keys[i]);
allocator.destroy(&(values[id]));
AllocatorTraits::destroy(allocator, &(values[id]));
}
}

Expand All @@ -303,7 +304,7 @@ namespace lemon {
Item it;
for (nf->first(it); it != INVALID; nf->next(it)) {
int id = nf->id(it);;
allocator.construct(&(values[id]), Value());
AllocatorTraits::construct(allocator, &(values[id]), Value());
}
}

Expand All @@ -317,7 +318,7 @@ namespace lemon {
Item it;
for (nf->first(it); it != INVALID; nf->next(it)) {
int id = nf->id(it);
allocator.destroy(&(values[id]));
AllocatorTraits::destroy(allocator, &(values[id]));
}
allocator.deallocate(values, capacity);
capacity = 0;
Expand Down

0 comments on commit f871b10

Please sign in to comment.