diff --git a/lemon/bits/array_map.h b/lemon/bits/array_map.h index 355ee00..42aded6 100644 --- a/lemon/bits/array_map.h +++ b/lemon/bits/array_map.h @@ -75,6 +75,7 @@ namespace lemon { typedef typename Notifier::ObserverBase Parent; typedef std::allocator Allocator; + typedef std::allocator_traits> AllocatorTraits; public: @@ -87,8 +88,8 @@ namespace lemon { Notifier* nf = Parent::notifier(); Item it; for (nf->first(it); it != INVALID; nf->next(it)) { - int id = nf->id(it);; - allocator.construct(&(values[id]), Value()); + int id = nf->id(it); + AllocatorTraits::construct(allocator, &(values[id]), Value()); } } @@ -101,8 +102,8 @@ namespace lemon { Notifier* nf = Parent::notifier(); Item it; for (nf->first(it); it != INVALID; nf->next(it)) { - int id = nf->id(it);; - allocator.construct(&(values[id]), value); + int id = nf->id(it); + AllocatorTraits::construct(allocator, &(values[id]), value); } } @@ -120,8 +121,8 @@ namespace lemon { Notifier* nf = Parent::notifier(); Item it; for (nf->first(it); it != INVALID; nf->next(it)) { - int id = nf->id(it);; - allocator.construct(&(values[id]), copy.values[id]); + int id = nf->id(it); + AllocatorTraits::construct(allocator, &(values[id]), copy.values[id]); } } @@ -216,17 +217,17 @@ namespace lemon { Value* new_values = allocator.allocate(new_capacity); Item it; for (nf->first(it); it != INVALID; nf->next(it)) { - int jd = nf->id(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. @@ -260,8 +261,8 @@ 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; @@ -269,7 +270,7 @@ namespace lemon { } 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()); } } @@ -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. @@ -289,7 +290,7 @@ namespace lemon { virtual void erase(const std::vector& 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])); } } @@ -302,8 +303,8 @@ namespace lemon { allocate_memory(); Item it; for (nf->first(it); it != INVALID; nf->next(it)) { - int id = nf->id(it);; - allocator.construct(&(values[id]), Value()); + int id = nf->id(it); + AllocatorTraits::construct(allocator, &(values[id]), Value()); } } @@ -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; diff --git a/lemon/path.h b/lemon/path.h index baa92c4..c3a1722 100644 --- a/lemon/path.h +++ b/lemon/path.h @@ -393,7 +393,7 @@ namespace lemon { data.resize(len); int index = 0; for (typename CPath::ArcIt it(path); it != INVALID; ++it) { - data[index] = it;; + data[index] = it; ++index; } } @@ -405,7 +405,7 @@ namespace lemon { int index = len; for (typename CPath::RevArcIt it(path); it != INVALID; ++it) { --index; - data[index] = it;; + data[index] = it; } } @@ -448,7 +448,9 @@ namespace lemon { Node *first, *last; - std::allocator alloc; + private: + typedef std::allocator Allocator; + typedef std::allocator_traits> AllocatorTraits; public: @@ -582,8 +584,8 @@ namespace lemon { void clear() { while (first != 0) { last = first->next; - alloc.destroy(first); - alloc.deallocate(first, 1); + AllocatorTraits::destroy(_allocator, first); + _allocator.deallocate(first, 1); first = last; } } @@ -595,8 +597,8 @@ namespace lemon { /// \brief Add a new arc before the current path void addFront(const Arc& arc) { - Node *node = alloc.allocate(1); - alloc.construct(node, Node()); + Node *node = _allocator.allocate(1); + AllocatorTraits::construct(_allocator, node, Node()); node->prev = 0; node->next = first; node->arc = arc; @@ -617,8 +619,8 @@ namespace lemon { } else { last = 0; } - alloc.destroy(node); - alloc.deallocate(node, 1); + AllocatorTraits::destroy(_allocator, node); + _allocator.deallocate(node, 1); } /// \brief The last arc of the path. @@ -628,8 +630,8 @@ namespace lemon { /// \brief Add a new arc behind the current path. void addBack(const Arc& arc) { - Node *node = alloc.allocate(1); - alloc.construct(node, Node()); + Node *node = _allocator.allocate(1); + AllocatorTraits::construct(_allocator, node, Node()); node->next = 0; node->prev = last; node->arc = arc; @@ -650,8 +652,8 @@ namespace lemon { } else { first = 0; } - alloc.destroy(node); - alloc.deallocate(node, 1); + AllocatorTraits::destroy(_allocator, node); + _allocator.deallocate(node, 1); } /// \brief Splice a path to the back of the current path. @@ -766,6 +768,9 @@ namespace lemon { } } + private: + Allocator _allocator; + }; /// \brief A structure for representing directed paths in a digraph. @@ -795,11 +800,11 @@ namespace lemon { /// \brief Default constructor /// /// Default constructor - StaticPath() : len(0), arcs(0) {} + StaticPath() : _len(0), _arcs(0) {} /// \brief Copy constructor /// - StaticPath(const StaticPath& cpath) : arcs(0) { + StaticPath(const StaticPath& cpath) : _arcs(0) { pathCopy(cpath, *this); } @@ -807,7 +812,7 @@ namespace lemon { /// /// This path can be initialized from any other path type. template - StaticPath(const CPath& cpath) : arcs(0) { + StaticPath(const CPath& cpath) : _arcs(0) { pathCopy(cpath, *this); } @@ -815,7 +820,7 @@ namespace lemon { /// /// Destructor of the path ~StaticPath() { - if (arcs) delete[] arcs; + if (_arcs) delete[] _arcs; } /// \brief Copy assignment @@ -887,7 +892,7 @@ namespace lemon { /// /// \pre \c n is in the [0..length() - 1] range. const Arc& nth(int n) const { - return arcs[n]; + return _arcs[n]; } /// \brief The arc iterator pointing to the n-th arc. @@ -896,26 +901,26 @@ namespace lemon { } /// \brief The length of the path. - int length() const { return len; } + int length() const { return _len; } /// \brief Return true when the path is empty. - int empty() const { return len == 0; } + int empty() const { return _len == 0; } /// \brief Erase all arcs in the digraph. void clear() { - len = 0; - if (arcs) delete[] arcs; - arcs = 0; + _len = 0; + if (_arcs) delete[] _arcs; + _arcs = 0; } /// \brief The first arc of the path. const Arc& front() const { - return arcs[0]; + return _arcs[0]; } /// \brief The last arc of the path. const Arc& back() const { - return arcs[len - 1]; + return _arcs[_len - 1]; } @@ -923,29 +928,29 @@ namespace lemon { template void build(const CPath& path) { - len = path.length(); - arcs = new Arc[len]; + _len = path.length(); + _arcs = new Arc[_len]; int index = 0; for (typename CPath::ArcIt it(path); it != INVALID; ++it) { - arcs[index] = it; + _arcs[index] = it; ++index; } } template void buildRev(const CPath& path) { - len = path.length(); - arcs = new Arc[len]; - int index = len; + _len = path.length(); + _arcs = new Arc[_len]; + int index = _len; for (typename CPath::RevArcIt it(path); it != INVALID; ++it) { --index; - arcs[index] = it; + _arcs[index] = it; } } private: - int len; - Arc* arcs; + int _len; + Arc* _arcs; }; ///////////////////////////////////////////////////////////////////////