Re: C++11 features, move semantics?



2015-01-28 14:00 GMT+01:00 Russel Winder <russel winder org uk>:
On Wed, 2015-01-21 at 11:36 +0100, François Legendre wrote:
Hi,

For range based loop, why not use the name of the element (and not the indice) ?

-    for(unsigned i = 0; i < names.size(); i++)
-      std::cout << names[i] << "." << std::endl;
+    for(const auto& i : names)
+      std::cout << i << "." << std::endl;

+    for(const auto& name : names)
+      std::cout << name << "." << std::endl;


What about using:

        for (auto&& name: names)

?
We want a const traversal ; it is less secure to code "auto&&".
---
François


--
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel winder ekiga net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel winder org uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]