Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. efficiency copy vector into a second vector

efficiency copy vector into a second vector

Scheduled Pinned Locked Moved ATL / WTL / STL
questiongraphics
5 Posts 4 Posters 0 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.
  • M Offline
    M Offline
    manustone
    wrote on last edited by
    #1

    Hi all I have to copy elements of a std::vector at the end of a second std::vector. What is the most efficient approach? I think that method insert is not very efficient (am I right?); what if I use copy in ? If also this is not good, what way can I follow? Kind Regards ManuStone

    Steve EcholsS C A 3 Replies Last reply
    0
    • M manustone

      Hi all I have to copy elements of a std::vector at the end of a second std::vector. What is the most efficient approach? I think that method insert is not very efficient (am I right?); what if I use copy in ? If also this is not good, what way can I follow? Kind Regards ManuStone

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #2

      Does

      insert(vec2.end(), vec1.begin(), vec1.end());

      work?


      - S 50 cups of coffee and you know it's on!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      1 Reply Last reply
      0
      • M manustone

        Hi all I have to copy elements of a std::vector at the end of a second std::vector. What is the most efficient approach? I think that method insert is not very efficient (am I right?); what if I use copy in ? If also this is not good, what way can I follow? Kind Regards ManuStone

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        manustone wrote:

        I think that method insert is not very efficient (am I right?); what if I use copy in ?

        Do you mean the copy constructor? I think performance is quite comparable to insertion method (as suggested by Steve Echols), but why don't you make a test?

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        [my articles]

        M 1 Reply Last reply
        0
        • C CPallini

          manustone wrote:

          I think that method insert is not very efficient (am I right?); what if I use copy in ?

          Do you mean the copy constructor? I think performance is quite comparable to insertion method (as suggested by Steve Echols), but why don't you make a test?

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          [my articles]

          M Offline
          M Offline
          manustone
          wrote on last edited by
          #4

          (Sorry for the delay) Thank you very much for your response! ManuStone

          1 Reply Last reply
          0
          • M manustone

            Hi all I have to copy elements of a std::vector at the end of a second std::vector. What is the most efficient approach? I think that method insert is not very efficient (am I right?); what if I use copy in ? If also this is not good, what way can I follow? Kind Regards ManuStone

            A Offline
            A Offline
            Andy Moore
            wrote on last edited by
            #5

            std::vector vec1; std::vector vec2; std::copy(vec1.begin(), vec1.end(), std::back_inserter(vec2));

            Pax Domini sit semper vobiscum

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups