c++ - 并行 std::lists,根据列表 B 中项目的状态删除列表 A 中的项目?

标签 c++ stdlist

我将如何完成以下任务?

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

我正在考虑针对列表 B 的 std::remove_if 思路,但是如果我这样做,我将如何删除列表 A 的项目?遗憾的是,不同列表的迭代器不兼容,除了使用手动实现之外,没有办法遍历列表并知道每个值的索引。

最佳答案

您可能要考虑使用结构列表而不是两个列表。然后你可以使用 remove_if 和其他列表函数。

关于c++ - 并行 std::lists,根据列表 B 中项目的状态删除列表 A 中的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16128464/

相关文章:

c++ - 派生和破坏封装,还是违反 DRY?

c++ - 从另一个列表的元素构造一个列表而不添加到堆内存

c++ - 如何在指向自定义类的指针列表中找到元素

c++ - std::list 的多元素插入是强异常安全的吗?

c++ - 使用自定义增量迭代二维 vector

c++ - 库中的 MinGW-w64 编译错误

c++ - 动态分配的控制台 I/O 的 Visual Studio 2015 问题

c++ - 针对非默认 glibc 的链接

c++ - std::list 的 const_iterator 与迭代器

c++ - 如果 list::remove() 用于不存在的元素,会返回什么?