[Dune-devel] EntityIterator inheriting from EntityPointer

Martin Nolte nolte at mathematik.uni-freiburg.de
Mon Jul 7 17:33:18 CEST 2014


Hi Oli,

in the depth of the darkest parts of my memory I find the following 
information about the historical development:

Conceptually, the entity iterator is an entity pointer. Therefore, 
EntityIterator has always been derived from EntityPointer to reflect this "is an".

The original facade classes then used a reinterpret_cast to cast an 
EntityIterator & into an EntityPointer &. As this trouble gcc-4.4 (and above) 
and is not covered by the C++ standard, the resolution was to use copy 
construction, i.e., you can now cast an EntityIterator into an EntityPointer, 
but no longer EntityInterator & into EntityPointer &.

To avoid unnecessary copying into entity pointer, you will find most binary 
operations on the entity pointer like this one:

template< class ItImp >
bool operator== ( const EntityPointer< GridImp, ItImp > &rhs ) const;

Due to the derivation, the const EntityIterator< ItImp > & casts into const 
EntityPointer< GridImp, ItImp > & and no copy is required, by the facades 
(whatever the implementations implicate is another story).

All this discussion never touched the point whether the "is an" relation 
should be reflected in facade class hierarchy. You can decouple them by 
copying the entire EntityPointer interface into the EntityIterator and making 
the two interoperable (i.e., operator== must work on any combination of the 
two). But this will only yield lots of code duplication. Additionally, it 
would IMHO shadow the concept of "is an".

Now, your question might be: Do I really need to compare entity pointers and 
entity iterators. Especially: Do I really need to compare a level iterator and 
a leaf iterator? But that's a can of worms I would not even dare touching.

Hope that sheds some light onto the situation,

Martin

On 07/07/2014 04:05 PM, Oliver Sander wrote:
> Dear Dune Developers,
> I recently noticed that the EntityIterator interface class still inherits
> from EntityPointer.  Is that for historical reasons only, or is there there
> still an actual reason today?
> Thanks,
> Oliver
>
>
>
> _______________________________________________
> Dune-devel mailing list
> Dune-devel at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-devel
>

-- 
Dr. Martin Nolte <nolte at mathematik.uni-freiburg.de>

Universität Freiburg                                   phone: +49-761-203-5630
Abteilung für angewandte Mathematik                    fax:   +49-761-203-5632
Hermann-Herder-Straße 10
79104 Freiburg, Germany




More information about the Dune-devel mailing list