3 ms·
I don't see what the problem is here, this is very readable to me. You want to find between the beginning and end of a list called v, for a value between y < i
by CountHackulus 15y ago
I don't see what the problem is here, this is very readable to me. You want to find between the beginning and end of a list called v, for a value between y < i < x. Admittedly the condition in the lambda could be better written, and the results should probably be called something other than i, but it's perfectly clear what's going on here.
Let's look at the equivalent C++98 loop:
int i = -1;
for(std::vector<int>::iterator iter = v.begin(); iter != v.end(); ++iter)
{
if(*iter > x && *iter < y)
{
i = *iter;
break;
}
}
It's not only much more verbose, but the types need to be expressly written, and what's going on isn't immediately obvious from the function name.
No, C++ will never win a beauty contest (I'd vote for D or Haskell personally), but it's great for expressibility, and the new C++11 changes make things more concise.
- kleiba 15y agoAgree completely. When you compare the new code to the C++98 one, it looks like a great improvement. But isn't that because C++98 simply sucked even more? As you say, when you compare it to languages like Haskell, even the new C++11 leaves something to be desired.