osuplusplus/include/va_args_util.hpp

73 lines
5.7 KiB
C++
Raw Normal View History

#pragma once
// https://stackoverflow.com/a/11994395 modified to fit my needs
#define FE_0(WHAT)
#define FE_1(WHAT, extra_arg, X) WHAT(extra_arg, X)
#define FE_2(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_1(WHAT, extra_arg, __VA_ARGS__)
#define FE_3(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_2(WHAT, extra_arg, __VA_ARGS__)
#define FE_4(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_3(WHAT, extra_arg, __VA_ARGS__)
#define FE_5(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_4(WHAT, extra_arg, __VA_ARGS__)
#define FE_6(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_5(WHAT, extra_arg, __VA_ARGS__)
#define FE_7(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_6(WHAT, extra_arg, __VA_ARGS__)
#define FE_8(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_7(WHAT, extra_arg, __VA_ARGS__)
#define FE_9(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_8(WHAT, extra_arg, __VA_ARGS__)
#define FE_10(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_9(WHAT, extra_arg, __VA_ARGS__)
#define FE_11(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_10(WHAT, extra_arg, __VA_ARGS__)
#define FE_12(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_11(WHAT, extra_arg, __VA_ARGS__)
#define FE_13(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_12(WHAT, extra_arg, __VA_ARGS__)
#define FE_14(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_13(WHAT, extra_arg, __VA_ARGS__)
#define FE_15(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_14(WHAT, extra_arg, __VA_ARGS__)
#define FE_16(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_15(WHAT, extra_arg, __VA_ARGS__)
#define FE_17(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_16(WHAT, extra_arg, __VA_ARGS__)
#define FE_18(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_17(WHAT, extra_arg, __VA_ARGS__)
#define FE_19(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_18(WHAT, extra_arg, __VA_ARGS__)
#define FE_20(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_19(WHAT, extra_arg, __VA_ARGS__)
#define FE_21(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_20(WHAT, extra_arg, __VA_ARGS__)
#define FE_22(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_21(WHAT, extra_arg, __VA_ARGS__)
#define FE_23(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_22(WHAT, extra_arg, __VA_ARGS__)
#define FE_24(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_23(WHAT, extra_arg, __VA_ARGS__)
#define FE_25(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_24(WHAT, extra_arg, __VA_ARGS__)
#define FE_26(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_25(WHAT, extra_arg, __VA_ARGS__)
#define FE_27(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_26(WHAT, extra_arg, __VA_ARGS__)
#define FE_28(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_27(WHAT, extra_arg, __VA_ARGS__)
#define FE_29(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_28(WHAT, extra_arg, __VA_ARGS__)
#define FE_30(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_29(WHAT, extra_arg, __VA_ARGS__)
#define FE_31(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_30(WHAT, extra_arg, __VA_ARGS__)
#define FE_32(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_31(WHAT, extra_arg, __VA_ARGS__)
#define FE_33(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_32(WHAT, extra_arg, __VA_ARGS__)
#define FE_34(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_33(WHAT, extra_arg, __VA_ARGS__)
#define FE_35(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_34(WHAT, extra_arg, __VA_ARGS__)
#define FE_36(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_35(WHAT, extra_arg, __VA_ARGS__)
#define FE_37(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_36(WHAT, extra_arg, __VA_ARGS__)
#define FE_38(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_37(WHAT, extra_arg, __VA_ARGS__)
#define FE_39(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_38(WHAT, extra_arg, __VA_ARGS__)
#define FE_40(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_39(WHAT, extra_arg, __VA_ARGS__)
#define FE_41(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_40(WHAT, extra_arg, __VA_ARGS__)
#define FE_42(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_41(WHAT, extra_arg, __VA_ARGS__)
#define FE_43(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_42(WHAT, extra_arg, __VA_ARGS__)
#define FE_44(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_43(WHAT, extra_arg, __VA_ARGS__)
#define FE_45(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_44(WHAT, extra_arg, __VA_ARGS__)
#define FE_46(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_45(WHAT, extra_arg, __VA_ARGS__)
#define FE_47(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_46(WHAT, extra_arg, __VA_ARGS__)
#define FE_48(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_47(WHAT, extra_arg, __VA_ARGS__)
#define FE_49(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_48(WHAT, extra_arg, __VA_ARGS__)
#define FE_50(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_49(WHAT, extra_arg, __VA_ARGS__)
#define NTH_ARG(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,NAME,...) NAME
#define FOR_EACH(action,extra_arg,...) NTH_ARG(_0,__VA_ARGS__,FE_50,FE_49,FE_48,FE_47,FE_46,FE_45,FE_44,FE_43,FE_42,FE_41,FE_40,FE_39,FE_38,FE_37,FE_36,FE_35,FE_34,FE_33,FE_32,FE_31,FE_30,FE_29,FE_28,FE_27,FE_26,FE_25,FE_24,FE_23,FE_22,FE_21,FE_20,FE_19,FE_18,FE_17,FE_16,FE_15,FE_14,FE_13,FE_12,FE_11,FE_10,FE_9,FE_8,FE_7,FE_6,FE_5,FE_4,FE_3,FE_2,FE_1,FE_0)(action,extra_arg,__VA_ARGS__)
// https://stackoverflow.com/a/2124385
#define ARG_COUNT(...) \
ARG_COUNT_(__VA_ARGS__,FILLER())
#define ARG_COUNT_(...) \
NTH_ARG(__VA_ARGS__)
// one more than in NTH_ARG to get the count
// instead of the index of the last element
#define FILLER() \
51,50, \
49,48,47,46,45,44,43,42,41,40, \
39,38,37,36,35,34,33,32,31,30, \
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9,8,7,6,5,4,3,2,1,0