我正在使用CLion集成开发环境编写我的C++项目。有时,IDE试图比我更聪明,并给我一些建议。我在代码检查过程中遇到了一个简单的问题(通过CLion)。它说下面的代码可以简化,尽管我认为这是我能想到的最简单的形式:
代码:
if (node.first >= 0 && node.first <= 45 &&
node.second >= 0 && node.second <= 30)
return true;
else
return false;
假设节点的类型为std::pair<int, int>
我从CLion集成开发环境中得到的建议如下:
代码检查注释:
Inspection info: This inspection finds the part of the code that can be simplified, e.g. constant conditions, identical if branches, pointless boolean expressions, etc.
你认为这还可以简化吗?
发布于 2019-05-20 01:21:01
CLion在暗示你这一点..。
if (node.first >= 0 && node.first <= 45 &&
node.second >= 0 && node.second <= 30)
return true;
else
return false;
可以重写为
return node.first >= 0 && node.first <= 45 &&
node.second >= 0 && node.second <= 30;
因为在控制语句中用作条件的表达式显然具有到true和false的自然转换。
https://stackoverflow.com/questions/56210221
复制相似问题