Loop types

Magnus Fromreide magfr@lysator.liu.se
Sat Sep 14 05:50:00 GMT 2013


Hi.

Looking at libstdc++ I came over this piece of code (in
regex_executor.h):

_Executor(_BiIter    __begin,
          _BiIter    __end,
          _ResultsT& __results,
          _FlagT     __flags,
          _SizeT     __size)
: _M_current(__begin), _M_end(__end), _M_results(__results),
  _M_flags(__flags)
{
  __size += 2;
  _M_results.resize(__size);
  for (auto __i = 0; __i < __size; __i++)
   _M_results[__i].matched = false;
}

I think the use of auto in the for statement is problematic since the
type of __i ends up as int while __size is an unsigned int.

Additionally I have a preference for pre-increment even if it makes no
difference in this case. 

I would thus propose to change the for statement from

  for (auto __i = 0; __i < __size; __i++)

to

  for (_SizeT __i = 0; __i < __size; ++__i)

/MF



More information about the Libstdc++ mailing list