Skip to content

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions