https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109400
Bug ID: 109400 Summary: Missing 'advance' optimizations for std::istreambuf_iterator Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- We have a custom overload of std::advance for std::istreambuf_iterator which operates directly on the streambuf's get area, instead of incrementing character by character. But it doesn't get used when calling std::next, because that calls std::advance without ADL, and the custom overload hasn't been declared yet. We either need to declare istreambuf_iterator and its std::advance, or add a custom overload of std::next. Additionally, std::ranges::advance is not specialized for std::istreambuf_iterator so just increments character by character. The ranges::advance(i, n) form should use std::advance. The ranges::advance(i, sentinel) form will already be optimal when the sentinel is the same type as the iterator, but will be slow when using default_sentinel_t. The ranges::advance(i, n, sentinel) form could be done efficiently, and has the advantage that it's not undefined if EOF is reached before advancing n times.