rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.9k stars 12.67k forks source link

Sort-of RFC: add `min!`, `max!` macros once namespacing lands #53501

Open richard-uk1 opened 6 years ago

richard-uk1 commented 6 years ago

Since you can namespace macros in rust 2018, maybe consider including min and max macros in std::cmp?

From a post about gamedev on rust

There’s no min! and max! macro. You need to write max(max(max(max(max(max, a), b), c), d), e) for example. I have a code with 15 max like this.

This seems like a macro you can write yourself easily enough. Is there something I’m missing?

macro_rules! max {
     ($e: expr) => { $e };
     ($e: expr, $($rest: tt)*) => { max($e, max!($($rest)*)) }
}
richard-uk1 commented 6 years ago

Doesn't seem like a big enough change for an RFC, whether it gets accepted or not.

CAD97 commented 6 years ago

Don't forget to make it trailing-comma-accepted: $(,)? with the kleene op or just another arm if not.