Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C++ Macro overload
#include <iostream> // General utility macro #define PP_CAT( A, B ) A ## B #define PP_EXPAND(...) __VA_ARGS__ // Macro overloading feature support #define PP_VA_ARG_SIZE(...) PP_EXPAND(PP_APPLY_ARG_N((PP_ZERO_ARGS_DETECT(__VA_ARGS__), PP_RSEQ_N))) #define PP_ZERO_ARGS_DETECT(...) PP_EXPAND(PP_ZERO_ARGS_DETECT_PREFIX_ ## __VA_ARGS__ ## _ZERO_ARGS_DETECT_SUFFIX) #define PP_ZERO_ARGS_DETECT_PREFIX__ZERO_ARGS_DETECT_SUFFIX ,,,,,,,,,,,0 #define PP_APPLY_ARG_N(ARGS) PP_EXPAND(PP_ARG_N ARGS) #define PP_ARG_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N,...) N #define PP_RSEQ_N 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 #define PP_OVERLOAD_SELECT(NAME, NUM) PP_CAT( NAME ## _, NUM) #define PP_MACRO_OVERLOAD(NAME, ...) PP_OVERLOAD_SELECT(NAME, PP_VA_ARG_SIZE(__VA_ARGS__))(__VA_ARGS__) // Usage example #define FOO(...) PP_MACRO_OVERLOAD(FOO, __VA_ARGS__) #define FOO_0() "Zero" #define FOO_1(X) "One" #define FOO_2(X, Y) "Two" #define FOO_3(X, Y, Z) "Three" int main() { std::cout << FOO() << "\n" << FOO(1) << "\n" << FOO(1, 2) << "\n" << FOO(1, 2, 3) << std::endl; }
run
|
edit
|
history
|
help
0
Compile time creation of class member stl container (const std::array) filled with elements.
Wide string conversion with multibyte chars and locale
Ελλάδα !!!!
#21
MSVC_example_GetAllocLength
Computing factorial of an integer with recursion and iteration [EDIT]
c++
#27
RVO hota hai bhenchod
ExtThes_Uniquify