[Dune] Iterators for fake reference types

Carsten Gräser graeser at math.fu-berlin.de
Fri Nov 20 12:07:22 CET 2009


Dear all,
while trying to run the matrix test with ScaledIdentityMatrix
and DiagonalMatrix the following question arose:

Suppose you have an iterator 'it' for a pseudo container returning
fake references of type 'RefT' that should behave similar to 'T&'.

This is e.g. done in std::vector<bool>, BitSetVector and the above
matrix classes. While RefT refers to an elementary type for
vector<bool> this is not true in the cases. Thus one would like
to call methods of RefT which is always safe in the temporary scope.
Taking addresses is obviously forbidden.

	(*it).f(); 	// OK
	&(*it);   	// not OK

The leeds to the ugly fact that you can not use

	it->f();

Since '->' does not allow creation of a temp object. The only 'solution'
I can imagine would be to return an auto_ptr to a RefT created on the
heap. However then

	(*it).f();
	it->f();

would do fundamentally different thing an the latter would
(unexpectedly for the user) be much slower.

Does anyone have idea I missed how to solve this ?

Regards
Carsten

-- 
----------------------------------------------------------------------
Carsten Gräser           | phone: +49-30 / 838-75349
Freie Universität Berlin | fax  : +49-30 / 838-54977
Institut für Mathematik  | email: graeser at math.fu-berlin.de
Arnimallee 6             |
14195 Berlin, Germany    | URL  : http://page.mi.fu-berlin.de/graeser
----------------------------------------------------------------------




More information about the Dune mailing list