Simple Print

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <stdio.h> #define NUM_ARGS_(X32, X31, X30, X29, X28, X27, X26, X25, \ X24, X23, X22, X21, X20, X19, X18, X17, X16, X15, X14, X13, \ X12, X11, X10, X9, X8, X7, X6, X5, X4, X3, X2, X1, N, ...) N #define NUM_ARGS(...) NUM_ARGS_(__VA_ARGS__, 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) #define EXPAND(X) X #define FIRSTARG(X, ...) (X) #define RESTARGS(X, ...) (__VA_ARGS__) #define FOREACH(MACRO, LIST) FOREACH_(NUM_ARGS LIST, MACRO, LIST) #define FOREACH_(N, M, LIST) FOREACH__(N, M, LIST) #define FOREACH__(N, M, LIST) FOREACH_##N(M, LIST) #define FOREACH_1(M, LIST) M LIST #define FOREACH_2(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_1(M, RESTARGS LIST) #define FOREACH_3(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_2(M, RESTARGS LIST) #define FOREACH_4(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_3(M, RESTARGS LIST) #define FOREACH_5(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_4(M, RESTARGS LIST) #define FOREACH_6(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_5(M, RESTARGS LIST) #define FOREACH_7(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_6(M, RESTARGS LIST) #define FOREACH_8(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_7(M, RESTARGS LIST) #define FOREACH_9(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_8(M, RESTARGS LIST) #define FOREACH_10(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_9(M, RESTARGS LIST) #define FOREACH_11(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_10(M, RESTARGS LIST) #define FOREACH_12(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_11(M, RESTARGS LIST) #define FOREACH_13(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_12(M, RESTARGS LIST) #define FOREACH_14(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_13(M, RESTARGS LIST) #define FOREACH_15(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_14(M, RESTARGS LIST) #define FOREACH_16(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_15(M, RESTARGS LIST) #define FOREACH_17(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_16(M, RESTARGS LIST) #define FOREACH_18(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_17(M, RESTARGS LIST) #define FOREACH_19(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_18(M, RESTARGS LIST) #define FOREACH_20(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_19(M, RESTARGS LIST) #define FOREACH_21(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_20(M, RESTARGS LIST) #define FOREACH_22(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_21(M, RESTARGS LIST) #define FOREACH_23(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_22(M, RESTARGS LIST) #define FOREACH_24(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_23(M, RESTARGS LIST) #define FOREACH_25(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_24(M, RESTARGS LIST) #define FOREACH_26(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_25(M, RESTARGS LIST) #define FOREACH_27(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_26(M, RESTARGS LIST) #define FOREACH_28(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_27(M, RESTARGS LIST) #define FOREACH_29(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_28(M, RESTARGS LIST) #define FOREACH_30(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_29(M, RESTARGS LIST) #define FOREACH_31(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_30(M, RESTARGS LIST) #define FOREACH_32(M, LIST) EXPAND(M FIRSTARG LIST) FOREACH_31(M, RESTARGS LIST) #define print_(X) << (X) << " " #define prints_(X) << (X) #define print(X...) std::cout FOREACH(print_,(X)) << std::endl #define printn(X...) std::cout FOREACH(print_,(X)) #define prints(X...) std::cout FOREACH(prints_,(X)) << std::endl #define printsn(X...) std::cout FOREACH(prints_,(X)) // print() space implicit between arguments and a newline at the end. // printn() No new-line. // prints() No space. // printsn() No new-line and no space. #define PrintOperatorDefine(Type) \ std::ostream& operator <<(std::ostream& Stream, Type In) struct hex{ size_t Val; }; struct ptr{ size_t Val; }; PrintOperatorDefine(hex) { printf("0x%lX",In.Val); return Stream; } PrintOperatorDefine(ptr) { printf("0x%.16lX",In.Val); return Stream; } int main() { print(hex{3227}); print(ptr{3227}); print(12,15,"Water"); printn("Type:"); prints("f",32); printsn("Type: s"); print(32); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines