是否有可能缩短这个方法...魔术在C++,用C#LINQ启发
bool check_if_any(set<int> &s, int x)
{
for (int i : s)
if (i == x)
return true;
return false;
}
...所以它看起来像C#LINQ的方式...
bool check_if_any(set<int> &s, int x)
{
return s.any(i => i == x);
}
...或者其他方式,但更短?我不知道C++中的lambdas,但我知道它们存在。所以我想这是可能的。
'套 s'复制整个集合? –
senfen
看看https://cpplinq.codeplex.com – Oliver
不知道这是你想要的,但'返回s.find(x)!= s.end();'更短。 – Heike