5 ms·
the readability issue here is in part that function arguments are purely positional in c++. a little over the top for this simple example, but you can always c
by leetcrew 2y ago
the readability issue here is in part that function arguments are purely positional in c++.
a little over the top for this simple example, but you can always create local variables to document intention.
auto initVal = 0;
auto accumulateOp = [](int a, b) {return a + b;};
return std::accumulate(x.begin(), x.end(), initVal, accumulateOp);
I'd prefer to see a for each loop over algorithms functions in such simple cases, but I'd prefer almost anything over direct indexing when it isn't necessary. when I see that in new code, my first thought is always "what am I missing here?".