Skip to content

SinglePassRangeConcept should support non-const range #133

@grtowel1510f

Description

@grtowel1510f

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 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:

#include <boost/range/adaptor/transformed.hpp>
#include <boost/coroutine2/coroutine.hpp>

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

int main() {
    using generator = coroutine<int>;
    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions