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

  • Home
  • SEARCH
  • 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 7969315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:13:04+00:00 2026-06-04T07:13:04+00:00

I have two std::list with objects: source_list and new_list . The goal is to

  • 0

I have two std::list with objects: source_list and new_list. The goal is to add objects from new_list to source_list starting from position_at_source_to_adding_new_from and with steps_between_new.

The problem with steps: source_list can be to short and new_list can be to large (or steps to big) and when doing std::advance(it, steps_between_new) iterator can go beyond the range of source_list and its will be undefined behavior.

How to check iterator before/after std::advance to be sure that we are at ranges? And when there is more objects at new_list that can be placed with steps between them – need to simple add there objects to the end of source list.

ps. sorry for my english, its hard to explain on not native language. any corrections are welcome to my text. thanks.

  • 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-06-04T07:13:05+00:00Added an answer on June 4, 2026 at 7:13 am

    Instead of calling advance, just call ++iterator as many times as needed. After each call, compare the iterator to end().

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

Sidebar

Related Questions

Say I have two containers storing pointers to the same objects: std::list<Foo*> fooList; std::vector<Foo*>
In my class I have two private members: std::list<MyObject> objects; MyObject *selecteObj; When an
Say you have a std::list of some class. There are two ways you can
I have std::list<Info> infoList in my application that is shared between two threads. These
Let's say I have two maps: typedef int Id; std::map<Id, std::string> idToStringMap; std::map<Id, double>
I have a relatively simple algorithm that walks an std::vector looking for two neighbouring
I have two classes generated by LINQ2SQL both from the same table so they
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
I have coworkers who occasionally use typedef to avoid typing. For example: typedef std::list<Foobar>

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.