boostorg / boostorg/range

SinglePassRangeConcept should support non-const range

Open
#133 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
45
Forks
104
PR merge metrics
No merged PRs in 30d

Description

A single pass range often can be consumed only once which implies mutability and negates constness, on the first consumption it becomes empty. SinglePassRangeConcept asserts [`const_constraints`](https://github.com/boostorg/range/blob/d6e0a32f2ee3094bbe237769d2dd8e4cb81f8bf6/include/boost/range/concepts.hpp#L299-L306) which is a requirement that cannot be met by many or most single pass ranges.

I will demonstrate using a boost coroutine with a range adaptor:
```cpp
#include
#include

using boost::adaptors::transformed;
using boost::coroutines2::coroutine;

int main() {
using generator = coroutine;
generator::pull_type g([](auto &yield) {
for (int i = 0; i < 10; i++) {
yield(i);
}
});

for (auto i: g | transformed([](int i) { return i + 10; })) {
}

return 0;
}
```

This code snippet does not compile because SinglePassRangeConcept asserts `const_constraints` which boost coroutine does not satisfy.

I propose to drop the const requirement for SinglePassRangeConcept because in simple terms, a single pass range isn't required to have a const iterator.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.