c++ - 如何使用循环检查等价性,如果不等价则执行一些代码?

标签 c++ design-patterns

我做了这样的事情:

for (vector<vector<int> > :: iterator it = result.begin(); it != it.end(); ++it) {
  if (equal(it->begin(), it->end(), triplet->begin()) {
    flag = 1;
    break;
  }
}
if (flag != 1) triplets.insert(triplet);

我想知道如何在没有“旗帜”的情况下做到这一点。谢谢。

最佳答案

编辑:代码更改后(flag==1 vs flag!=1),此答案不再正确

因为你 break 你可以把你的代码放在 for:

for (vector<vector<int> > :: iterator it = result.begin(); it != it.end(); ++it) {
  if (equal(it->begin(), it->end(), triplet->begin()) {
    triplets.insert(triplet);
    break;
  }
}

关于c++ - 如何使用循环检查等价性,如果不等价则执行一些代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13828658/

相关文章:

C# 工厂设计模式

design-patterns - 您能解释一下 Context 设计模式吗?

c++ - 在 Windows 中使用 gmail 作为 smtp 中继器在 c++ 中发送邮件

c++ - boost 1.53 python fatal error LNK1104 boost_python-vc110-mt-gd-1_53.lib

c++ - 如何在 C++ 中获取 Wmi 连接的 SeSecurityPrivilege

c++字符串到char *的隐式转换匹配错误的函数签名

php - 实现 "soft"保存或修改工作流的最佳方式是什么?

java - 具有子类和所需参数的构建器设计模式?

c++ - 可变参数 lambda 与可变参数模板函数 : stricly equivalent?

java - 方法设计方法,其中方法采用可变数量的参数值