https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116958
Bug ID: 116958 Summary: [missed optimization] std::views::transform loses track of the range size Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: avi at scylladb dot com Target Milestone: --- Consider ``` #include <ranges> #include <span> #include <vector> #include <functional> std::vector<int> add1(std::span<int> r) { return r | std::views::transform(std::bind_front(std::plus<int>(), 1)) | std::ranges::to<std::vector>(); } ``` If I comment out the line calling transform(), it compiles to a call to operator new + memcpy. As is, it compiles to a traditional expanding vector loop. Since transform() doesn't change the size, it could have returned a sized_range which to()/vector<> could have used to reserve the right size in advance. https://godbolt.org/z/xaae1oMnf