Skip to content

Instantly share code, notes, and snippets.

@mrkishi
Created September 22, 2020 01:48
Show Gist options
  • Save mrkishi/bffb145c3a4be6e2ca2911e7198acdb6 to your computer and use it in GitHub Desktop.
Save mrkishi/bffb145c3a4be6e2ca2911e7198acdb6 to your computer and use it in GitHub Desktop.
macro_rules! count
macro_rules! count {
() => { 0 };
($($half:tt $_:tt)*) => { count!($($half)*) * 2 };
($one:tt $($half:tt $_:tt)*) => { count!($($half)*) * 2 + 1 };
}
const TOTAL: usize = count!(+++++++);
pub fn main() {
println!("{}", TOTAL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment