https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100070
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> --- Note to self/Patrick: Measure whether it helps to specialize transform_view's iterator so that when _Base_iter is __normal_iterator we unwrap it and store a raw pointer. Also, I suspect the indirections in return std::__invoke(*_M_parent->_M_fun, *_M_current); are making the optimizer give up. We have an indirection to the parent to access the semi-regular box, which has its own indirections. Maybe we could just get rid of the semi-regular box for a function pointer and store a function pointer (i.e. decay_t<Fp>) directly. That would have the same syntax (i.e. operator*) to access it as the semi-regular box, but would be less abstraction to un-abstract. And maybe store a function pointer directly in the transform_view iterator, so we don't need to go to the parent to get it on every dereference. Barry pointed out that range-v3 elides the use of semi-regular box for some cases, and he confirmed that storing a function pointer in the iterator helps.