3 ms·
There's much cooler approach: https://veykril.github.io/tlborm/decl-macros/building-blocks/counting.html#bit-twiddling https://veykril.github.io/tlborm/decl-mac
by afdbcreid 5y ago
There's much cooler approach: https://veykril.github.io/tlborm/decl-macros/building-blocks/counting.html#bit-twiddling https://veykril.github.io/tlborm/decl-macros/building-blocks....
macro_rules! count {
() => (0);
($odd:tt ($a:tt $b:tt)*) => ((count!($($a)*) << 1) | 1);
(($a:tt $b:tt)*) => (count!($($a)*) << 1);
}
It uses bit twiddling to avoid generating very big AST and eventually crashing the compiler. Though I have to admit using `${count()}` is better.