YaR*_*mgl -4 c++ variables relational
我想知道(只是为了知道)是否有办法用更简单的代码执行以下指令:(C++)
if(a > b && a > c && a > d)
Run Code Online (Sandbox Code Playgroud)
有可能用这样的东西替换它:
if(a > b, c, d)
Run Code Online (Sandbox Code Playgroud)
使用std::max(std::initializer_list<T>)从<algorithm>类似如下标题:
#include <iostream>
#include <algorithm>
int main()
{
if(4 > std::max({2,3,6}))
std::cout << "greater\n";
else
std::cout << "not greater\n";
}
Run Code Online (Sandbox Code Playgroud)