https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104858

            Bug ID: 104858
           Summary: ranges::minmax double dereferences first
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

In
https://github.com/gcc-mirror/gcc/blob/bded0d549fdfdc1328b2c0189dc5f8593b4cbe42/libstdc%2B%2B-v3/include/bits/ranges_algo.h#L3087:

the initial result is constructed as:

minmax_result<range_value_t<_Range>> __result = {*__first, *__first};

If *__first performs actually does work (maybe it's a transformed iterator),
then this is wasteful. But more importantly, if *__first gives you an rvalue
reference, then this moves from that iterator twice.

I think the standard requires ranges::minmax(v | views::as_rvalue) to actually
be valid (assuming an as_rvalue adaptor that ensures that the reference type is
an rvalue).

Reply via email to