From c07e2596b5fb3297ad3ad6b426f6d17acfa462c2 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Sat, 22 Nov 2014 08:08:33 +0100 Subject: [PATCH] Improved comparison operators for TriaAccessorBase The previous commit was a bit too aggressive because it is still useful to catch the case when comparing iterators to two different triangulations (leading to infinite loops). Therefore, I now merely extended the assertion to not trigger when one of the two objects is default constructed, i.e., does contain a null pointer to tria. The comparison then does not need tria == a.tria because invalid iterators use invalid cell and level index, too (leading to !=). --- include/deal.II/grid/tria_accessor.templates.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index 97232e4268..9781cc01da 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -121,8 +121,9 @@ inline bool TriaAccessorBase::operator == (const TriaAccessorBase &a) const { - return ((tria == a.tria) && - (present_level == a.present_level) && + Assert (tria == a.tria || tria == 0 || a.tria == 0, + TriaAccessorExceptions::ExcCantCompareIterators()); + return ((present_level == a.present_level) && (present_index == a.present_index)); } @@ -133,8 +134,9 @@ inline bool TriaAccessorBase::operator != (const TriaAccessorBase &a) const { - return ((tria != a.tria) || - (present_level != a.present_level) || + Assert (tria == a.tria || tria == 0 || a.tria == 0, + TriaAccessorExceptions::ExcCantCompareIterators()); + return ((present_level != a.present_level) || (present_index != a.present_index)); } -- 2.39.5