[Dune-devel] EntityIterator inheriting from EntityPointer

Oliver Sander sander at igpm.rwth-aachen.de
Mon Jul 7 17:48:58 CEST 2014


Am 07.07.2014 17:33, schrieb Martin Nolte:
> 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).
> 

Hi Martin,
thanks for the information.  It reflects the things I remember.

> 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".
> 

Indeed, I am not really convinced of the 'is an' anymory.  Interoperability is convenient every know and
then, but I start finding the current inheritance construction confusing.  Maybe we should introduce all those
explicit conversion operators someday.  I may be longer, but easier to understand.

Cheers,
Oliver

> 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
>>
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 534 bytes
Desc: OpenPGP digital signature
URL: <https://lists.dune-project.org/pipermail/dune-devel/attachments/20140707/7160a023/attachment.sig>


More information about the Dune-devel mailing list