3 ms·
That's terrible! The main operation, addition, is completely hidden magic! But the completely trivial calls to .begin() and .end() are explicit! Why would I wa
by lupire 2y ago
That's terrible! The main operation, addition, is completely hidden magic! But the completely trivial calls to
.begin() and .end() are explicit!
Why would I want to add by default?
- psychoslave 2y agoMaybe the idea is that you overload your favored default as a + operator? Even more baffling certainly, but at this point I wouldn’t even be surprised this was considered a compelling argument in the mind of whoever settled this API choice. :D
- constantcrying 2y agoWhat is hidden? It's a reduce on + starting with 0, hardly anything subtle.
- jcelerier 2y ago> The main operation, addition, is completely hidden magic the main operation is reduction which is fairly basic computer science and taught in any non-BS curriculum - https://en.wikipedia.org/wiki/Reduction_operator https://en.wikipedia.org/wiki/Reduction_operator (or https://en.wikipedia.org/wiki/Fold_(higher-order_function) https://en.wikipedia.org/wiki/Fold_(higher-order_function) which is the standard way to introduce this concept ; check in particular the table showcasing all the implementations in various languages). The standard reduction for a set of numbers to a number that is likely going to be the very first example in your textbook is addition.
- Dylan16807 2y agoThe reduction is explicit. That's not what the complaint is about. And it's more about implementation than the actual result. The actual operation is addition. I don't care if it's the first example, that doesn't mean you should hide it. Imagine if print did hello world by default.
- o11c 2y agostd::ranges::fold_left (since C++23) can take a range directly instead of a separated pair of iterators, and requires the explicit add.