fork download
  1. #include <iostream>
  2.  
  3. // for when the template parameter pack is empty...
  4. int doCountZeros() {
  5. return 0;
  6. }
  7.  
  8. template <typename Arg, typename... Args>
  9. int doCountZeros(Arg firstArg, Args... otherArgs) {
  10. return int(firstArg == 0) + doCountZeros(otherArgs...);
  11. }
  12.  
  13. template <typename... Args>
  14. int countZeros(Args... args) {
  15. return doCountZeros(args...);
  16. }
  17.  
  18. int main() {
  19. int varA = 1, varB = 0, varC = 3, varD = 0;
  20. std::cout << countZeros(varA, varB, varC, varD);
  21. return 0;
  22. }
Success #stdin #stdout 0s 4344KB
stdin
Standard input is empty
stdout
2