Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Range Based for loop vs iterator for STL Containers
Qt 6.11 is out! See what's new in the release blog

Range Based for loop vs iterator for STL Containers

Scheduled Pinned Locked Moved Unsolved C++ Gurus
7 Posts 3 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vinoth Rajendran4
    wrote on last edited by
    #1

    Hi All,

    Like to know when to prefer, range based for loop vs iterators for STL Containers.

    Any pointers on advantage and disadvantages of both method would be also helpful.

    Thanks!

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by Kent-Dorfman
      #2

      range based for loops cannot modify the length of the container. iterators facilitate adding or deleting elements.

      The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

      V 1 Reply Last reply
      2
      • Kent-DorfmanK Kent-Dorfman

        range based for loops cannot modify the length of the container. iterators facilitate adding or deleting elements.

        V Offline
        V Offline
        Vinoth Rajendran4
        wrote on last edited by
        #3

        @Kent-Dorfman : Thanks for the input.
        If we are not going to modify the container, then which one provide better performance ?

        J.HilkJ 1 Reply Last reply
        0
        • V Vinoth Rajendran4

          @Kent-Dorfman : Thanks for the input.
          If we are not going to modify the container, then which one provide better performance ?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Vinoth-Rajendran4 said in Range Based for loop vs iterator for STL Containers:

          If we are not going to modify the container, then which one provide better performance ?

          not using STL Containers


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          V 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @Vinoth-Rajendran4 said in Range Based for loop vs iterator for STL Containers:

            If we are not going to modify the container, then which one provide better performance ?

            not using STL Containers

            V Offline
            V Offline
            Vinoth Rajendran4
            wrote on last edited by
            #5

            @J-Hilk : for STL Container

            J.HilkJ 1 Reply Last reply
            0
            • V Vinoth Rajendran4

              @J-Hilk : for STL Container

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Vinoth-Rajendran4 the only real way to know is benchmarking it.

              https://quick-bench.com


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              V 1 Reply Last reply
              2
              • J.HilkJ J.Hilk

                @Vinoth-Rajendran4 the only real way to know is benchmarking it.

                https://quick-bench.com

                V Offline
                V Offline
                Vinoth Rajendran4
                wrote on last edited by
                #7

                @J-Hilk : Thanks for the test suite link.

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved