Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-46961

Please add for loop which iterates over constant reference to containers

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • P3: Somewhat important
    • None
    • 5.5.1, 5.6
    • None
    • All

    Description

      Current foreach loop iterates over copy of container. This add some small overhead for Qt-containers and makes full container copy for stl containers which is error prone to 1) change of container type or 2) misunderstanding/not-awareness of how foreach works.

      So generally this can be alternative for current foreach which will work good with Qt and std container.
      Current foreach can be helpful only if some signal-slot calls (which can change the container) happens inside loop. But I think it is better to clearly write such loops ... I mean straightly showing of making of container copy and iterating over it (so that misunderstandings like here:
      https://codereview.qt-project.org/#/c/115389/1/src/widgets/accessible/complexwidgets.cpp
      will never happens).

      The code which is already written and work with foreach should continue to work so it is only possible to add another macro for constant reference to containers loops.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            progrev Prav Ogrev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes