20-Sep-2013 14:55, Szymon Gatner пишет:
On Friday, 20 September 2013 at 10:47:52 UTC, Dmitry Olshansky wrote:
20-Sep-2013 14:00, Jacob Carlborg пишет:
On 2013-09-20 11:37, Szymon Gatner wrote:
If only std algorithms took containers (by that I mean things that
container for accepts too) as arguments (and not iterators)... even in
the form of new functions like foreach_all, transform_all etc.
Can't a container be a range as well?
For Christ sake no, no and no. For starters range skips/drops elements
when iterating, and thusly iteration has its own state that is useless
for a container otherwise.
That would be a filtering range which adds additional logic that costs
exactly the same as an if() statement inside a for loop when filtering
on condition manually.
Filtering is just an adapter.
Better examples are traversing e.g. binary-tree depth-first in-order, or
post-order and that would require state.
Again it's easy to miss by looking at built-in arrays.
TL;DR: Suboptimal, unnatural and error prone are keywords.
Why would it be suboptimal?
If said tree needs to be a range I would be horrified to see how it
manges to be at the same time a range that (for the sake of example)
traverses said tree depth-first in-order.
Not even talking about trees having no one "natural" range over them.
--
Dmitry Olshansky