Skip to content

Instantly share code, notes, and snippets.

@Masstronaut
Last active October 10, 2016 07:55
Show Gist options
  • Save Masstronaut/8b66b40fb0358e717093b9872ab7305b to your computer and use it in GitHub Desktop.
Save Masstronaut/8b66b40fb0358e717093b9872ab7305b to your computer and use it in GitHub Desktop.
#include <iostream>
template<typename Ret, typename... Args>
constexpr int arg_count(Ret(*)(Args...)){
return sizeof...(Args);
}
void foo(int, float, double, char){}
int foo2(float, int, char*){return 0;}
void foo3(){}
int main(){
std::cout << arg_count(foo) << std::endl; // 4
std::cout << arg_count(foo2) << std::endl;// 3
std::cout << arg_count(foo3) << std::endl;// 0
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment