Skip to content

Commit

Permalink
collection: fix SortedArray container (#35)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yerden authored and dingmaotu committed Apr 9, 2018
1 parent 3c09910 commit 2ff32c6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Collection/SortedArray.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ 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<T>*sorter=NULL):
SortedArray(SortComparer<T>*sorter,bool owned=true,bool unique=true):
Collection(owned,sorter),
m_unique(unique),
m_sorter(sorter==NULL?new GenericSortComparer<T>():sorter){}
~SortedArray() {SafeDelete(m_sorter);}
m_sorter(sorter){}
~SortedArray() {clear();}

// ConstIterator interface
ConstIterator<T>*constIterator() const {return new ConstSortedArrayIterator<T>(GetPointer(this));}
// Iterator interface
Iterator<T>*iterator() {return new SortedArrayIterator<T>(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();}
Expand Down

0 comments on commit 2ff32c6

Please sign in to comment.