RE: [Dev-C++] a trivial question on for loops
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2001-10-17 09:36:30
|
> -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Luigi Santillo > Sent: Tuesday, October 16, 2001 7:40 PM > To: dev...@li... > Subject: [Dev-C++] a trivial question on for loops >=20 >=20 > Hello everybody, >=20 > I know this is an easy one, but what I've seen on a C++ book=20 > puzzled me. >=20 > Consider the two pieces of code that follow: >=20 > 1) as found on a recent C++ book > list<int> l_int; > // ... fill the list with a few intergers > for (list<int>::const_iterator i =3D l_int.begin(), i !=3D=20 > l_int.end(); ++i) > // ... do something >=20 > 2) as I used to know > list<int> l_int; > // ... fill the list with a few intergers=20 > list<int>::const_iterator stop =3D l_int.end(); for=20 > (list<int>::const_iterator i =3D l_int.begin(), i !=3D stop; ++i) > // ... do something >=20 > The two pieces are equivalent, but the second one is more=20 > efficient. Do you=20 > agree with me? Well at terms of speed they should be the same, at terms of space the second occupies more (1 variable). As i have told before templates tend to be expanded inline in compilation time so the speed is the same. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com * Alternative URL: http://run.to/noicys |