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.
Instead of calling
advance, just call++iteratoras many times as needed. After each call, compare the iterator toend().