From: Martin Kronbichler Date: Sat, 22 Nov 2014 07:08:33 +0000 (+0100) Subject: Improved comparison operators for TriaAccessorBase X-Git-Tag: v8.2.0-rc1~49^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c07e2596b5fb3297ad3ad6b426f6d17acfa462c2;p=dealii.git 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 !=). --- 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)); }