Skip to content

Incorrect std::max_element translation #454

Description

@joaotgouveia

The current std::max_element for std::vector is as follows:

fn f42(a0: Ptr<u8>, a1: Ptr<u8>) -> Ptr<u8> {
    let __count = a1.get_offset() - a0.get_offset();
    let max_index = PtrValueIter::new(&a0, __count)
        .enumerate()
        .max_by_key(|&(_, val)| val)
        .map(|(idx, _)| idx)
        .unwrap_or(0);

    a0 + max_index
}

According to the documentation for std::max_element, if there are multiple greatest elements, it returns the iterator to the first one of them. The current translation uses Rust's max_by_key, which returns the last element when there are multiple greatest elements.

This is also the case for vector's f94 and algorithm's f8 rules.

No activity

Activity on this issue will appear here.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions