4 ms·
Thanks for the link, that seems very useful. I recently had to work around this by transforming a list (a, b, c, d) into something like 1+1+1+1+0 to get a count
by codeflo 5y ago
Thanks for the link, that seems very useful. I recently had to work around this by transforming a list (a, b, c, d) into something like 1+1+1+1+0 to get a count. What this RFC proposes looks so much less painful.
- afdbcreid 5y agoThere'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.