Parallel std::lists, removing items in list A based on state of items in list B?

StackOverflow https://stackoverflow.com/questions/16128464

  •  11-04-2022
  •  | 
  •  

문제

How would I accomplish the following?

List A is a series of Foos, list B is a series of doubles representing time remaining until the Foo at the ith position of List A is removed. That is, if a double in List B is less than zero, the Foo at the same position in List A as the less than zero double in List B is removed from List A and then the less-than-zero double is removed from List B.

List A:
A B C D E

List B (in seconds):
1.0 0.33 0.0 5.0 0.01

//1 tick of 0.33 seconds

List B:
0.67 0.0 -0.33 4.67 -0.32

//Remove offending List A elements based on state of List B
List A:
A B D

//Remove invalid List B elements
List B:
0.67 0.0 4.67

I'm thinking something along the lines of std::remove_if for List B, but how would I remove the items for List A if I do that? Sadly, iterators of different lists aren't compatible and, except using manual implementations, there is no way to iterate through a list AND know the index of each value.

도움이 되었습니까?

해결책

You might want to consider using a list of structures instead of two lists. Then you can use remove_if and other list functions.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top