Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5958737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:35:08+00:00 2026-05-22T18:35:08+00:00

Say I have a vector / list whatever of ints populated with 2300 values

  • 0

Say I have a vector / list whatever of ints populated with 2300 values
I want to be able to easily slice this into 4 vectors /lists (not necessarily of equal size).
e.g.

vec1 ( elements 0 - 500 )
vec2 ( elements 501 - 999)
vec3 ( elements 1001 - 1499)

etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:35:09+00:00Added an answer on May 22, 2026 at 6:35 pm

    A common way to do it would be to use the one container, and just define separate iterator ranges over it.

    std::vector<int> vec(2300);
    
    it0 = vec.begin();
    it1 = vec.begin() + 500;
    it2 = vec.begin() + 1000;
    it3 = vec.begin() + 1500;
    it4 = vec.begin() + 2000;
    it5 = vec.end();
    

    Now, the first range is simply defined by the iterators it0 and it1. The second by it1 and it2, and so on.

    So, if you want to apply a function to every element in the third range, you’d simply do this:

    std::for_each(it2, it3, somefunc);
    

    Actually copying the elements into separate containers may be unnecessary, and would carry a performance cost.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a vector: (def data [Hello World Test This]) And I want
Say I have a list and a vector, and I want to zip them
Let's say I have this vector v <- c(1:100) And I want to get
Let's say I have a vector (array, list, whatever...) V of N elements, let's
Say I have a method that returns this. Vector[ (PkgLine, Tree) ]() I want
Say you have a simple class with some storage data structure (list, vector, queue,
Let's say I have a: std::vector<std::list<Node> > And let's say Node is: class Node
Say I have two containers storing pointers to the same objects: std::list<Foo*> fooList; std::vector<Foo*>
Let's just say i have a Vector of Strings, and I want to output
So lets say I have a list of numbers and I want to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.