]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add operator < to iterators, to allow a partial ordering which is needed if we want...
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 5 May 1998 13:14:37 +0000 (13:14 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 5 May 1998 13:14:37 +0000 (13:14 +0000)
git-svn-id: https://svn.dealii.org/trunk@253 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/grid/tria_iterator.h

index f5464c04947920b2b6383797e3e5fec5d5b88f66..4658a20095344fa2e8cda41b8cefe7b105e0254b 100644 (file)
@@ -307,6 +307,25 @@ class TriaRawIterator : public bidirectional_iterator<Accessor,int>{
                                      */
     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)<level(b) or
+                                     * (level(a)==level(b) and index(a)<index(b)).
+                                     *
+                                     * Comparing iterators of which one or
+                                     * both are invalid is an error. The
+                                     * past-the-end iterator is always
+                                     * ordered last. Two past-the-end
+                                     * iterators rank the same, thus false
+                                     * is returned in that case.
+                                     */
+    bool operator < (const TriaRawIterator &) const;
+    
                                     /**@name Advancement of iterators*/
                                     /*@{*/
                                     /**
@@ -380,10 +399,12 @@ class TriaRawIterator : public bidirectional_iterator<Accessor,int>{
                                      *  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<dim,Accessor>::state () const {
 
 
 
+template <int dim, class Accessor>
+inline
+bool TriaRawIterator<dim,Accessor>::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 <int dim, class Accessor>
 inline
 TriaRawIterator<dim,Accessor> &
@@ -737,6 +774,14 @@ TriaRawIterator<dim,Accessor>::operator -- () {
 
 
 
+template <int dim, class Accessor>
+inline
+void TriaRawIterator<dim,Accessor>::print (ostream &out) const {
+  out << accessor.level() << "." << accessor.index();
+};
+
+
+
 template <int dim, class Accessor>
 inline
 ostream & operator << (ostream &out, const TriaRawIterator<dim,Accessor> &i) {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.