Skip to content
Snippets Groups Projects
Commit 820fd91f authored by Fons Rademakers's avatar Fons Rademakers
Browse files

iterator of TOrdCollection objects can be now used with std::for_each,

std::find_if, std::count_if and the like.


git-svn-id: http://root.cern.ch/svn/root/trunk@23531 27541ba8-7e3a-0410-8455-c3a389f83636
parent 6542ce84
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,9 @@
#include "TSeqCollection.h"
#endif
#include <iterator>
class TOrdCollectionIter;
......@@ -52,6 +55,8 @@ private:
public:
enum { kDefaultCapacity = 1, kMinExpand = 8, kShrinkFactor = 2 };
typedef TOrdCollectionIter Iterator_t;
TOrdCollection(Int_t capacity = kDefaultCapacity);
~TOrdCollection();
void Clear(Option_t *option="");
......@@ -90,7 +95,10 @@ public:
// //
//////////////////////////////////////////////////////////////////////////
class TOrdCollectionIter : public TIterator {
class TOrdCollectionIter : public TIterator,
public std::iterator<std::bidirectional_iterator_tag,
TObject*, std::ptrdiff_t,
const TObject**, const TObject*&> {
private:
const TOrdCollection *fCol; //collection being iterated
......
......@@ -459,13 +459,11 @@ Int_t TOrdCollection::BinarySearch(TObject *obj)
ClassImp(TOrdCollectionIter)
//______________________________________________________________________________
TOrdCollectionIter::TOrdCollectionIter(const TOrdCollection *col, Bool_t dir)
TOrdCollectionIter::TOrdCollectionIter(const TOrdCollection *col, Bool_t dir): fCol(col), fDirection(dir)
{
// Create collection iterator. By default the iteration direction
// is kIterForward. To go backward use kIterBackward.
fCol = col;
fDirection = dir;
Reset();
}
......@@ -477,6 +475,7 @@ TOrdCollectionIter::TOrdCollectionIter(const TOrdCollectionIter &iter) : TIterat
fCol = iter.fCol;
fDirection = iter.fDirection;
fCursor = iter.fCursor;
fCurCursor = iter.fCurCursor;
}
//______________________________________________________________________________
......@@ -489,6 +488,7 @@ TIterator &TOrdCollectionIter::operator=(const TIterator &rhs)
fCol = rhs1.fCol;
fDirection = rhs1.fDirection;
fCursor = rhs1.fCursor;
fCurCursor = rhs1.fCurCursor;
}
return *this;
}
......@@ -502,6 +502,7 @@ TOrdCollectionIter &TOrdCollectionIter::operator=(const TOrdCollectionIter &rhs)
fCol = rhs.fCol;
fDirection = rhs.fDirection;
fCursor = rhs.fCursor;
fCurCursor = rhs.fCurCursor;
}
return *this;
}
......@@ -532,6 +533,8 @@ void TOrdCollectionIter::Reset()
fCursor = 0;
else
fCursor = fCol->GetSize() - 1;
fCurCursor = fCursor;
}
//______________________________________________________________________________
......@@ -540,7 +543,7 @@ bool TOrdCollectionIter::operator!=(const TIterator &aIter) const
// This operator compares two TIterator objects.
if (nullptr == (&aIter))
return fCurCursor;
return (fCurCursor < fCol->GetSize());
if (aIter.IsA() == TOrdCollectionIter::Class()) {
const TOrdCollectionIter &iter(dynamic_cast<const TOrdCollectionIter &>(aIter));
......@@ -555,7 +558,7 @@ bool TOrdCollectionIter::operator!=(const TOrdCollectionIter &aIter) const
// This operator compares two TOrdCollectionIter objects.
if (nullptr == (&aIter))
return fCurCursor;
return (fCurCursor < fCol->GetSize());
return (fCurCursor != aIter.fCurCursor);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment