-
-
Save killercup/8f21ec5c2eae07762143 to your computer and use it in GitHub Desktop.
Rust min! and max! macros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
thanks