Skip to content

Tracking Issue for cmp_splat (Variadic min and max) #160728

Description

@bushrat011899

Feature gate: #![feature(cmp_splat)]
Zulip: #t-libs-api/api-changes > variadic min/max

This is a tracking issue for variadic cmp::min and cmp::max functions. Currently, these are separate functions named smallest and largest. To allow variadic support, #![feature(splat)] is enabled in core. See #153629 for further details.

Public API

// core::cmp

// Private implementation detail
impl(self) const trait TupleReduce: Tuple {
    type Item;
    fn reduce<F: [const] Destruct + [const] FnMut(Self::Item, Self::Item) -> Self::Item>(self, f: F) -> Self::Item;
}

impl<T> TupleReduce for (T, ...) { /* ... */ }

#[must_use]
pub const fn smallest<T: [const] Ord + [const] Destruct>(
    #[rustc_splat] vals: impl [const] TupleReduce<Item = T>,
) -> T;

#[must_use]
pub const fn largest<T: [const] Ord + [const] Destruct>(
    #[rustc_splat] vals: impl [const] TupleReduce<Item = T>,
) -> T;

Note that with #[rustc_splat], the signature of smallest and largest is any of fn(T) -> T through to fn(T, T, ..) -> T (up to twelve arguments). Twelve has been chosen as an arbitrary limit and can be changed.

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

  • Should we replace min and max (and their _by(_key) alternatives), or offer these new functions under a separate name?

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-splat`#![feature(splat)]` https://github.com/rust-lang/rust/issues/153629S-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions