Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
If you are on C++11 (or newer), it should be possible to use variadic templates to write a simple (compile-time) function to count the number of arguments: template<typename... Ts> constexp...
#1: Initial revision
If you are on C++11 (or newer), it should be possible to use [variadic templates](https://en.cppreference.com/w/cpp/language/parameter_pack.html) to write a simple (compile-time) function to count the number of arguments: ```cpp template<typename... Ts> constexpr int countArgs(const Ts&... args) { return sizeof...(args); } ``` With this function, we can go ahead and write the desired macro as follows: ```cpp #define F(...) f(countArgs(__VA_ARGS__), __VA_ARGS__) ``` This should work no matter what the types of the variadic arguments are.