- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个这样的用户定义结构:
struct Cell{
int dirty;
double data;
Cell* c;
// bool operator==(const struct Cell& other) {
// /* I am not sure if I need this function here...*/
// }
};
然后,我定义了一个这样的列表:
list<Cell> cell_list;
我要做的是删除“cell_list”中满足条件的所有元素
(certain_cell.dirty == 1)
谁能告诉我如何有效地实现上述操作?
最佳答案
在没有 lambda 的情况下(即 C++11 之前的版本):
#include <iostream>
#include <list>
struct Cell {
bool dirty;
Cell(bool dirt=false) : dirty(dirt) { }
};
typedef std::list<Cell> CellList;
bool isDirty(const Cell& c) {
return c.dirty;
}
int main() {
CellList cells;
cells.push_back(Cell());
cells.push_back(Cell());
cells.push_back(Cell(true));
cells.push_back(Cell());
cells.push_back(Cell(true));
for (CellList::const_iterator i=cells.begin(); i!=cells.end(); ++i)
std::cout << i->dirty << '\n';
std::cout << '\n';
cells.remove_if( isDirty );
for (CellList::const_iterator i=cells.begin(); i!=cells.end(); ++i)
std::cout << i->dirty << '\n';
std::cout << '\n';
}
关于c++ - 删除 std :list<User_Define> that satisfy certain conditions? 中元素的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31507766/
我写了一个我认为是 quite interesting question 的答案,但不幸的是,在我发布之前,该问题已被作者删除。我在这里重新发布问题的摘要和我的答案,以防其他人有用。 假设我有一个 S
有没有办法写约束: C t1 t2 :: Constraint 如果 t2 与 t1 匹配,它“满足”(这是正确的词)。 例如: C (forall a. Num a => a -> a -> a)
我正在尝试用这段代码求解方程: a = [-0.0008333 -0.025 -0.6667 -20]; length_OnePart = 7.3248; xi = -6.4446; yi = -16
我知道我可以关闭 MySQL 中的安全模式,所以我不会尝试解决这个问题。 我有一个简单的表格: create table rubbish( id int auto_increment prim
尝试刷新我的 sencha extjs 应用程序并总是收到此错误: 命令: sencha 应用程序刷新 sencha 应用升级 总是同样的错误: [ERR] Cannot satisfy requir
我正在尝试为我的项目创建一个测试套件,HaskSplit在我的 .cabal 配置中: -- Initial HaskSplit.cabal generated by cabal init. For
我有 pc/sc 读卡器和非接触式卡(mifare 卡),我可以连接到该卡,并且我也成功执行 getdate 命令,但是当我想进行身份验证时,我看到此错误“6982:安全状态不满足”我已经尝试了这 3
简而言之,流程如下: inputChannel->transformer->firstOutboundAdapter->pollingOutboundAdapter 概要:inputChannel 接
这个问题在这里已经有了答案: Why do try!() and ? not compile when used in a function that doesn't return Option o
我正在尝试切片矢量并在 Rust 中同时打印它。这是我的代码: fn main() { let a = vec![1, 2, 3, 4]; println!("{:?}", a[1..
我正在尝试自定义约束 菜单栏类: import UIKit class ManuBar: UIView { override init(frame: CGRect) { sup
我遇到了这个问题,我有一个聊天服务器需要与托管在 aws 中的 lambda 服务进行通信,但云前端会引发以下错误。 BODY: ERROR: The request could not be s
我有一个包含Arc>的结构,我试图添加一个获取self所有权的方法,并将所有权移到新线程中并启动它。但是,我得到了错误 error[E0277]: the trait bound `std::sync
我遇到了一个编译错误,似乎突出显示了我对类型系统不了解的内容。 我想将字符串转换为整数,如果字符串不是有效整数,则带有自定义 panic 消息。我做一个match在 Result由 parse() 返
这是应用过滤器后复制数据的代码。 Sub read_excel_file(path_to_current_work_book As String, path_to_destination_work
我们有一个 shell 脚本,可以自动准备虚拟环境,然后在其中运行测试。部分脚本安装要求: pip install -r requirements.txt 当脚本多次运行时,它会针对每个要求打印一条警
总是遇到 FoodTracker 教程;遵循此步骤:“实现自定义控件” https://developer.apple.com/library/content/referencelibrary/Get
我收到此错误: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in th
我有一个 UITableViewCell我正在创建,并且我正在使用带有完全在代码中构建的约束的自动布局。 虽然应用程序中的实际输出很好(即,它看起来就像我设计的那样),但我收到了著名的“无法同时满足约
这个问题在这里已经有了答案: Disable autolayout constraint error messages in debug console output in Xcode (5 个回答)
我是一名优秀的程序员,十分优秀!