Skip to content

Instantly share code, notes, and snippets.

@segfo
Created August 2, 2017 14:54
Show Gist options
  • Save segfo/923bdd4f9b719d8667e914fac9e27e32 to your computer and use it in GitHub Desktop.
Save segfo/923bdd4f9b719d8667e914fac9e27e32 to your computer and use it in GitHub Desktop.
最小値、最大値を取得
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(){
let min=min!(3,2,10,0);
let max=max!(3,2,10,0);
println!("min:{}\nmax:{}",min,max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment