我只能在我的程序中插入 10 行(严格的)代码。我已经优化了编程,使其变得简洁。我已经发布了下面的代码。
if (std::find(outvar.begin(), outvar.end(), line[x].tokens[0]) == outvar.end() || (std::find(inputs.begin(), inputs.end(), line[x].tokens[4]) == inputs.end())
{
cerr << "Undefined variable " << endl;
exit(1);
}
if (opr[x].type == "MUL" && opr[x1].asap_value == my_cycle + 1)
{
opr[x1].asap_value = my_cycle + 2;
update_slack();
update_matrix(opr[x1].opid, 0);
}
if (latency < (opr[p2].asap_value + opr[p2].latency_op - 1) || opr[p2].asap_value == 0)
{
cerr << "Latency value is too less for this circuit \n"; return -1;
}
仅此一项就需要 10 行,而且我还必须添加 2 行强制代码。我无法进一步减少它。基本上我希望将 err(cout) 语句与 exit (return) 语句组合成一个语句。
任何帮助将不胜感激。
谢谢
最佳答案
您可以使用逗号将其全部合并为一行:
opr[x1].asap_value = my_cycle + 2, update_slack(), update_matrix(opr[x1].opid, 0);
不确定这是否被视为作弊。您还没有具体说明规则是什么。
关于c++ - 无法减少代码(cout与exit结合),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27322893/