Skip to content

Instantly share code, notes, and snippets.

@jswrenn
Created December 3, 2018 00:22
Show Gist options
  • Save jswrenn/8aea0aec3c635cb8942a2ae8d3d8fe6b to your computer and use it in GitHub Desktop.
Save jswrenn/8aea0aec3c635cb8942a2ae8d3d8fe6b to your computer and use it in GitHub Desktop.
macro_rules! pairs{
() => {};
($h : expr, $($t : expr,)*) =>
{
println!("({},{})", $h, $h);
$(println!("({},{})", $h, $t);)*
$(println!("({},{})", $t, $h);)*
pairs!{$($t,)*}
}
}
macro_rules! pairs{
({} { $($r: expr),* }) => {};
({$lh : expr, $($lt : expr,)*} { $($r: expr),* }) =>
{
$(println!("({},{})", $lh, $r);)*
pairs!{{$($lt,)*} {$($r),*}}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment