Skip to content

Wrong result with deque range input #144

Description

@oysstu

The following code gives wrong results when the line to parse is assigned to a deque (code)

#include <scn/scan.h>
#include <scn/ranges.h>
#include <deque>
#include <iostream>
#include <string_view>

int main() {
    std::string_view line("123456,654321");
    
    std::deque<char> dq;
    dq.assign(line.begin(), line.end());
    
    scn::ranges::subrange range(dq.begin(), dq.end());

    auto result = scn::scan<int, int>(range, "{},{}");
    if(result) {
        auto [v0, v1] = result->values();
        std::cout << "Result: " << v0 << ", " << v1 << "\n";
    } else {
        std::cout << "Failed: " << result.error().msg() << "\n";
    }
}

Which prints Result: 123456, 6. Adding a space after the comma in both the format string and input line yields the expected result. I guess that takes a different code path. I've also hit many cases of parsing result being EOF or "Argument list not exhausted", but these are seemingly random and I haven't found a consistent way to reproduce them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions