This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Loop types


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]