Skip to content

Instantly share code, notes, and snippets.

Created September 30, 2015 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/b2e1b43aab2415932f0b to your computer and use it in GitHub Desktop.
Save anonymous/b2e1b43aab2415932f0b to your computer and use it in GitHub Desktop.
Shared via Rust Playground
macro_rules! max {
($x:expr) => ( $x );
($x:expr, $($xs:expr),+) => {
{
use std::cmp::max;
max($x, max!( $($xs),+ ))
}
};
}
macro_rules! min {
($x:expr) => ( $x );
($x:expr, $($xs:expr),+) => {
{
use std::cmp::min;
min($x, min!( $($xs),+ ))
}
};
}
fn main() {
println!("{:?}", max!(2, 5, 9, -42, 5));
println!("{:?}", min!(2, 5, 9, -42, 5));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment