From aee8d0e245dc646a73daea212af7b142f0b3c0f4 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 5 May 1998 13:14:37 +0000 Subject: [PATCH] Add operator < to iterators, to allow a partial ordering which is needed if we want to use associative containers with iterators as keys. git-svn-id: https://svn.dealii.org/trunk@253 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/tria_iterator.h | 53 ++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/deal.II/deal.II/include/grid/tria_iterator.h b/deal.II/deal.II/include/grid/tria_iterator.h index f5464c0494..4658a20095 100644 --- a/deal.II/deal.II/include/grid/tria_iterator.h +++ b/deal.II/deal.II/include/grid/tria_iterator.h @@ -307,6 +307,25 @@ class TriaRawIterator : public bidirectional_iterator{ */ bool operator != (const TriaRawIterator &) const; + /** + * Offer a weak ordering of iterators, + * which is needed to make #map#s with + * iterators being keys. An iterator + * pointing to an element #a# is + * less than another iterator pointing + * to an element #b# if + * level(a){ * Return the state of the iterator. */ IteratorState state () const; - - void print (ostream &out) const { - out << accessor.level() << "." << accessor.index(); - }; + + /** + * Print the iterator in the form + * #level.index# to #out#. + */ + void print (ostream &out) const; @@ -713,6 +734,22 @@ IteratorState TriaRawIterator::state () const { +template +inline +bool TriaRawIterator::operator < (const TriaRawIterator &i) const { + Assert (state() != invalid, ExcDereferenceInvalidObject()); + Assert (i.state() != invalid, ExcDereferenceInvalidObject()); + + return ((((accessor.level() < i.accessor.level()) || + ((accessor.level() == i.accessor.level()) && + (accessor.index() < i.accessor.index())) ) && + (state()==valid) && + (i.state()==valid) ) || + ((state()==valid) && (i.state()==past_the_end))); +}; + + + template inline TriaRawIterator & @@ -737,6 +774,14 @@ TriaRawIterator::operator -- () { +template +inline +void TriaRawIterator::print (ostream &out) const { + out << accessor.level() << "." << accessor.index(); +}; + + + template inline ostream & operator << (ostream &out, const TriaRawIterator &i) { -- 2.39.5