
12.11.2013 21:13, Eric Niebler:
The commenter on my blog claims this extra check is optimized away by a smart compiler like gcc. He says[^1]:
[...]
It remains to be seen how well compilers can optimized several stacked range adapters, but at least in the simple cases we don't have to accept compromise.
Thank you for note. For such simple case it is not that surprising (especially when "static single assignment form" is used). Another example where wrapper can add overhead is something like std::copy_n - where it is possible to do zero checks on iterator per loop iteration (though, there will be check on "external" integer). But nevertheless, D-style InputRanges are useful on their own. And still - I think it is the best form to represent InputRanges, it catches semantic of underlying concept very accurately (though, other categories of D ranges are controversial). Speculating a bit further on new concepts, it is possible to make something like: while(!empty(i)) { use(*i); ++i; } // ... --i; while(!empty(i)) { use(*i); --i; } (perhaps "empty" is not the right name) -- Evgeny Panasyuk