Skip to content

<algorithm>: ranges::minmax initializes minmax_result with the moved value #2900

@hewillk

Description

@hewillk

minmax_result<_Vty> _Found = {static_cast<_Vty>(*_UFirst), static_cast<_Vty>(*_UFirst)};

This is basically GCC PR104858, which has been resolved in libstdc++.

#include <algorithm>
#include <string>
#include <vector>
#include <iostream>

int main() {
  std::vector<std::string> v{"1", "0"};
  auto [min, max] = std::ranges::minmax(
    std::ranges::subrange{
      std::make_move_iterator(v.begin()),
      std::make_move_iterator(v.end())});
  std::cout << min << " " << max << "\n"; // only print 0 in MSVC-STL
}

https://godbolt.org/z/nM5a1Y9Gr

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!rangesC++20/23 ranges

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions