[Dune] 'auto&&' or 'const auto&' ?

Atgeirr Rasmussen Atgeirr.Rasmussen at sintef.no
Mon Oct 12 17:16:33 CEST 2015


Hi Dune,

I am curious about why you require auto&& (starting with Dune 2.4 according to the web site)?
Are the iterators using proxy objects?

For general range-for loops I am not sure how I could get const-ness of these (const auto&& would
not be a universal const-reference would it)? I usually prefer to make my objects const if possible
(to prevent myself from making errors), but the auto&& will enable me to modify the range, unless
the range itself is const.

Atgeirr



12. okt. 2015 kl. 16.22 skrev Steffen Müthing <steffen.muething at iwr.uni-heidelberg.de<mailto:steffen.muething at iwr.uni-heidelberg.de>>:

Hi Bernd,

Am 12.10.2015 um 15:50 schrieb Bernd Flemisch <bernd at iws.uni-stuttgart.de<mailto:bernd at iws.uni-stuttgart.de>>:

Dear Dune,

should I use 'auto&&' or 'const auto&' in a range-based for-loop over the entities of a Dune GridView?

On the one hand, there is
https://www.dune-project.org/doc/doxygen/html/group__GIIteration.html#_details
which says "**always** use 'auto&&'"

On the other hand, there is
http://conan2.iwr.uni-heidelberg.de/git/pdelab/dune-pdelab/commit/d97c563807cd4f9aaa872dfee57c668eda12db59
together with
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63506
which indicates that a GCC bug is triggered when using 'auto&&‘.

yes, it’s all quite a mess: Basically, the standard (and important people like Stroustrup and Sutter) say that you
should *always* use auto&& in a range-based for loop, but GCC has this bug that sometimes causes a compilation
failure if the range-based for appears inside a function template, so you have to use const auto&.

So, the (rather unfortunate) advice is: You should use auto&&, but you can’t if you target current GCC due to a bug in
GCC. In that case, you have to use const auto&.

We should probably update the Doxygen documentation to explain the issue (I forgot about that when I discovered the compiler
b) because we’ll be stuck with the problem for the foreseeable future - the bug is still present in the GCC 6 snapshot from
the beginning of September that I have available on my machine, and the GCC Bugzilla bug hasn’t seen any attention in a long
time. Apart from that, the bug is in GCC 5, which we will have to support for a few years to come…

So I think the documentation needs to explain this issue.

Steffen


Kind regards
Bernd

--
_______________________________________________________________

Bernd Flemisch                         phone: +49 711 685 69162
IWS, Universität Stuttgart             fax:   +49 711 685 60430
Pfaffenwaldring 61            email:bernd at iws.uni-stuttgart.de<http://iws.uni-stuttgart.de>
D-70569 Stuttgart            url:www.hydrosys.uni-stuttgart.de<http://stuttgart.de>
_______________________________________________________________


_______________________________________________
Dune mailing list
Dune at dune-project.org<mailto:Dune at dune-project.org>
http://lists.dune-project.org/mailman/listinfo/dune


_______________________________________________
Dune mailing list
Dune at dune-project.org<mailto:Dune at dune-project.org>
http://lists.dune-project.org/mailman/listinfo/dune

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20151012/b595e3ad/attachment.htm>


More information about the Dune mailing list