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
Forum Updated to NodeBB v4.3 + New Features

Range Based for loop vs iterator for STL Containers

Scheduled Pinned Locked Moved Unsolved C++ Gurus
7 Posts 3 Posters 742 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 23 Feb 2022, 15:33 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
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 23 Feb 2022, 21:19 last edited by Kent-Dorfman
      #2

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

      V 1 Reply Last reply 24 Feb 2022, 06:50
      2
      • K Kent-Dorfman
        23 Feb 2022, 21:19

        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 24 Feb 2022, 06:50 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 1 Reply Last reply 24 Feb 2022, 06:51
        0
        • V Vinoth Rajendran4
          24 Feb 2022, 06:50

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

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 24 Feb 2022, 06:51 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 24 Feb 2022, 07:15
          0
          • J J.Hilk
            24 Feb 2022, 06:51

            @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 24 Feb 2022, 07:15 last edited by
            #5

            @J-Hilk : for STL Container

            J 1 Reply Last reply 24 Feb 2022, 07:17
            0
            • V Vinoth Rajendran4
              24 Feb 2022, 07:15

              @J-Hilk : for STL Container

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 24 Feb 2022, 07:17 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 24 Feb 2022, 08:14
              2
              • J J.Hilk
                24 Feb 2022, 07:17

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

                https://quick-bench.com

                V Offline
                V Offline
                Vinoth Rajendran4
                wrote on 24 Feb 2022, 08:14 last edited by
                #7

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

                1 Reply Last reply
                1

                1/7

                23 Feb 2022, 15:33

                • Login

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