On 03/05/2010 07:16 AM, Edwin Leuven wrote:
Abdelrazak Younes wrote:
On 03/05/2010 11:56 AM, Edwin Leuven wrote:
now when looping i write something like this:
row_type const nrows = row_info.size();
for (row_type r = 0; r < nrows; ++r) {
are compilers these days smart enough so that we can simply write:
for (row_type r = 0; r < row_info.size(); ++r) {
I guess it depends of the constness of row_info...
it's a non-const std::vector
what if i declared
row_type nrows() const {return row_info.size();}
and then do
for (row_type r = 0; r < nrows(); ++r)
?
I think gcc would give you a warning, to the effect of "Qualifier on
return value is ignored". This is because row_type is not of object type.
Moreover, you could perfectly well do:
for (row_type r = 0; r < nrows(); ++r)
row_info.clear();
if row_info is non-const. Then nrows() returns 0 on the second time
through, and the loop terminates, as it should. This suggests a reason that
for (row_type r = 0; r < row_info.size(); ++r) {
might be a little safer than
row_type const nrows = row_info.size();
for (row_type r = 0; r < nrows; ++r) {
when row_info is non-const.
Richard