From 2ff32c6d7d9ee93937fe57ba55654d1899412a78 Mon Sep 17 00:00:00 2001 From: yerden Date: Tue, 10 Apr 2018 05:49:34 +0600 Subject: [PATCH] collection: fix SortedArray container (#35) Changes: * fix constructor to require explicit SortComparer object since GenericSortComparer may fail in the runtime due to absence of `>` and `<` operators. * fix clear() method to adhere to Collection behaviour; * call clear() from destructor. --- Collection/SortedArray.mqh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Collection/SortedArray.mqh b/Collection/SortedArray.mqh index 07ef5b2..2454161 100644 --- a/Collection/SortedArray.mqh +++ b/Collection/SortedArray.mqh @@ -39,11 +39,11 @@ public: // owned: flag restricts destructor to delete array elements // unique: flag allows add()-ing of identical elements // sorter: array sorting implementation - SortedArray(bool owned=true,bool unique=true,SortComparer*sorter=NULL): + SortedArray(SortComparer*sorter,bool owned=true,bool unique=true): Collection(owned,sorter), m_unique(unique), - m_sorter(sorter==NULL?new GenericSortComparer():sorter){} - ~SortedArray() {SafeDelete(m_sorter);} + m_sorter(sorter){} + ~SortedArray() {clear();} // ConstIterator interface ConstIterator*constIterator() const {return new ConstSortedArrayIterator(GetPointer(this));} @@ -51,7 +51,7 @@ public: Iterator*iterator() {return new SortedArrayIterator(GetPointer(this),m_owned);} // Collection interface - void clear() {m_array.clear();} + void clear() {if(m_owned) m_array.clear(); else m_array.resize(0);} bool add(T value); bool remove(const T value); int size() const {return m_array.size();}