Created
September 9, 2022 12:48
-
-
Save MikuroXina/0907d4c42f657af2a566e14778630817 to your computer and use it in GitHub Desktop.
Generate permutations on macro arguments in Rust.
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! pairs { | |
| ($macro:ident; $($items:literal),*) => { | |
| pairs!(@ $macro; $($items),*; $($items),*); | |
| }; | |
| (@ $macro:ident; $x:literal; $($ys:literal),*) => { | |
| $( | |
| $macro!($x, $ys); | |
| )* | |
| }; | |
| (@ $macro:ident; $x:literal, $($xs:literal),*; $($ys:literal),*) => { | |
| $( | |
| $macro!($x, $ys); | |
| )* | |
| pairs!(@ $macro; $($xs),*; $($ys),*); | |
| }; | |
| } |
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! triplets { | |
| ($macro:ident; $($items:literal),*) => { | |
| triplets!(@ $macro; $($items),*; $($items),*; $($items),*); | |
| }; | |
| (@ $macro:ident; $x:literal; $y:literal; $($zs:literal),*) => { | |
| $( | |
| $macro!($x, $y, $zs); | |
| )* | |
| }; | |
| (@ $macro:ident; $x:literal; $y:literal, $($ys:literal),*; $($zs:literal),*) => { | |
| $( | |
| $macro!($x, $y, $zs); | |
| )* | |
| triplets!(@ $macro; $x; $($ys),*; $($zs),*); | |
| }; | |
| (@ $macro:ident; $x:literal, $($xs:literal),*; $y:literal, $($ys:literal),*; $($zs:literal),*) => { | |
| $( | |
| $macro!($x, $y, $zs); | |
| )* | |
| triplets!(@ $macro; $($xs),*; $y, $($ys),*; $($zs),*); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment