From 5a5f9bc76f1fd482e88b9123f2c5916b42765057 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sun, 4 Feb 2024 01:55:49 +0800 Subject: [PATCH] perf: remove /Zc:preprocessor required for MSVC --- CMakeLists.txt | 2 +- README.md | 1 - README_en.md | 1 - include/reflection/jsonization.hpp | 205 +++++++++++++++-------------- test/serializing_test.cpp | 13 +- 5 files changed, 115 insertions(+), 107 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb1fb26..598dced 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ option(BUILD_TESTING "Build testing" ON) set(CMAKE_CXX_STANDARD 17) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") - add_compile_options("/utf-8" "/W4" "/Zc:preprocessor") + add_compile_options("/utf-8" "/W4") else() add_compile_options("-Wall;-Wextra;-Wpedantic;-mtune=native") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") diff --git a/README.md b/README.md index 4636138..5120a68 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,6 @@ A modern all-platform Json/Json5 parser/serializer, which is header-only and use ``` - **meojson** 仅依赖 STL, 但需要 c++17 标准 -- 若使用 MSVC,请在项目中添加 `/Zc:preprocessor` - 若使用 AppleClang,请在项目中添加 `-Wno-gnu-zero-variadic-macro-arguments` ## 序列化 diff --git a/README_en.md b/README_en.md index 0760ec4..07d678d 100644 --- a/README_en.md +++ b/README_en.md @@ -25,7 +25,6 @@ A modern all-platform Json/Json5 parser/serializer, which is header-only and use ``` - **meojson** only depends on STL, but requires c++17 standard -- For MSVC, please add `/Zc:preprocessor` to your project - For AppleClang, please add `-Wno-gnu-zero-variadic-macro-arguments` to your project ## Serializing diff --git a/include/reflection/jsonization.hpp b/include/reflection/jsonization.hpp index 40b09fc..3868464 100644 --- a/include/reflection/jsonization.hpp +++ b/include/reflection/jsonization.hpp @@ -102,126 +102,131 @@ namespace json::_private_macro #define _MEOJSON_CONCATENATE1(arg1, arg2) _MEOJSON_CONCATENATE2(arg1, arg2) #define _MEOJSON_CONCATENATE2(arg1, arg2) arg1##arg2 +#define _MEOJSON_EXPAND(x) x + #define _MEOJSON_FOR_EACH_0(pred, ...) #define _MEOJSON_FOR_EACH_1(pred, x, ...) pred(x) -#define _MEOJSON_FOR_EACH_2(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_1(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_3(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_2(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_4(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_3(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_5(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_4(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_6(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_5(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_7(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_6(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_8(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_7(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_9(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_8(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_10(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_9(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_11(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_10(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_12(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_11(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_13(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_12(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_14(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_13(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_15(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_14(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_16(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_15(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_17(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_16(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_18(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_17(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_19(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_18(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_20(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_19(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_21(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_20(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_22(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_21(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_23(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_22(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_24(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_23(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_25(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_24(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_26(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_25(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_27(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_26(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_28(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_27(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_29(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_28(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_30(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_29(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_31(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_30(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_32(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_31(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_33(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_32(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_34(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_33(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_35(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_34(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_36(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_35(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_37(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_36(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_38(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_37(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_39(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_38(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_40(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_39(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_41(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_40(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_42(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_41(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_43(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_42(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_44(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_43(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_45(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_44(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_46(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_45(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_47(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_46(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_48(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_47(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_49(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_48(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_50(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_49(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_51(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_50(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_52(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_51(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_53(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_52(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_54(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_53(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_55(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_54(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_56(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_55(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_57(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_56(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_58(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_57(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_59(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_58(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_60(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_59(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_61(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_60(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_62(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_61(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_63(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_62(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH_64(pred, x, ...) pred(x) _MEOJSON_FOR_EACH_63(pred, __VA_ARGS__) +#define _MEOJSON_FOR_EACH_2(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_1(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_3(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_2(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_4(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_3(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_5(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_4(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_6(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_5(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_7(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_6(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_8(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_7(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_9(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_8(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_10(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_9(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_11(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_10(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_12(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_11(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_13(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_12(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_14(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_13(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_15(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_14(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_16(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_15(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_17(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_16(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_18(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_17(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_19(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_18(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_20(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_19(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_21(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_20(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_22(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_21(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_23(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_22(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_24(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_23(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_25(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_24(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_26(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_25(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_27(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_26(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_28(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_27(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_29(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_28(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_30(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_29(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_31(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_30(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_32(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_31(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_33(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_32(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_34(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_33(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_35(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_34(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_36(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_35(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_37(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_36(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_38(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_37(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_39(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_38(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_40(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_39(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_41(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_40(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_42(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_41(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_43(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_42(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_44(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_43(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_45(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_44(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_46(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_45(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_47(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_46(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_48(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_47(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_49(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_48(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_50(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_49(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_51(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_50(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_52(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_51(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_53(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_52(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_54(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_53(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_55(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_54(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_56(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_55(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_57(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_56(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_58(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_57(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_59(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_58(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_60(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_59(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_61(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_60(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_62(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_61(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_63(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_62(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH_64(pred, x, ...) pred(x) _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_63(pred, __VA_ARGS__)) #define _MEOJSON_ARG_COUNT(...) \ - _MEOJSON_ARG_COUNT1(0, ##__VA_ARGS__, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 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) + _MEOJSON_EXPAND(_MEOJSON_ARG_COUNT1(0, ##__VA_ARGS__, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 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)) #define _MEOJSON_ARG_COUNT1(_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, _51, _52, _53, _54, _55, \ _56, _57, _58, _59, _60, _61, _62, _63, _64, N, ...) \ N -#define _MEOJSON_FOR_EACH_(N, pred, ...) _MEOJSON_CONCATENATE(_MEOJSON_FOR_EACH_, N)(pred, __VA_ARGS__) -#define _MEOJSON_FOR_EACH(pred, ...) _MEOJSON_FOR_EACH_(_MEOJSON_ARG_COUNT(__VA_ARGS__), pred, __VA_ARGS__) +#define _MEOJSON_FOR_EACH_(N, pred, ...) _MEOJSON_EXPAND(_MEOJSON_CONCATENATE(_MEOJSON_FOR_EACH_, N)(pred, __VA_ARGS__)) +#define _MEOJSON_FOR_EACH(pred, ...) \ + _MEOJSON_EXPAND(_MEOJSON_FOR_EACH_(_MEOJSON_EXPAND(_MEOJSON_ARG_COUNT(__VA_ARGS__)), pred, __VA_ARGS__)) #define _MEOJSON_VARNAME(x) _MEOJSON_CONCATENATE(_meojson_jsonization_, x) #define _MEOJSON_KEY_VALUE(x) _MEOJSON_STRINGIZE(x), x, } // namespace json::_private_macro -// if you are using MSVC, please add "/Zc:preprocessor" to your project -#define MEO_TOJSON(...) \ - json::value to_json() const \ - { \ - return json::_jsonization_helper::dumper()._to_json(_MEOJSON_FOR_EACH(_MEOJSON_KEY_VALUE, __VA_ARGS__) \ - json::_jsonization_helper::va_arg_end {}); \ +#define MEO_TOJSON(...) \ + json::value to_json() const \ + { \ + return json::_jsonization_helper::dumper()._to_json(_MEOJSON_EXPAND( \ + _MEOJSON_FOR_EACH(_MEOJSON_KEY_VALUE, __VA_ARGS__)) json::_jsonization_helper::va_arg_end {}); \ } -// if you are using MSVC, please add "/Zc:preprocessor" to your project -#define MEO_CHECKJSON(...) \ - bool check_json(const json::value& _MEOJSON_VARNAME(in)) const \ - { \ - std::string _MEOJSON_VARNAME(error_key); \ - return check_json(_MEOJSON_VARNAME(in), _MEOJSON_VARNAME(error_key)); \ - } \ - bool check_json(const json::value& _MEOJSON_VARNAME(in), std::string& _MEOJSON_VARNAME(error_key)) const \ - { \ - return json::_jsonization_helper::checker()._check_json(_MEOJSON_VARNAME(in), _MEOJSON_VARNAME(error_key), \ - _MEOJSON_FOR_EACH(_MEOJSON_KEY_VALUE, __VA_ARGS__) \ - json::_jsonization_helper::va_arg_end {}); \ +#define MEO_CHECKJSON(...) \ + bool check_json(const json::value& _MEOJSON_VARNAME(in)) const \ + { \ + std::string _MEOJSON_VARNAME(error_key); \ + return check_json(_MEOJSON_VARNAME(in), _MEOJSON_VARNAME(error_key)); \ + } \ + bool check_json(const json::value& _MEOJSON_VARNAME(in), std::string& _MEOJSON_VARNAME(error_key)) const \ + { \ + return json::_jsonization_helper::checker()._check_json( \ + _MEOJSON_VARNAME(in), _MEOJSON_VARNAME(error_key), \ + _MEOJSON_EXPAND(_MEOJSON_FOR_EACH(_MEOJSON_KEY_VALUE, __VA_ARGS__)) \ + json::_jsonization_helper::va_arg_end {}); \ } -// if you are using MSVC, please add "/Zc:preprocessor" to your project -#define MEO_FROMJSON(...) \ - bool from_json(const json::value& _MEOJSON_VARNAME(in)) \ - { \ - std::string _MEOJSON_VARNAME(error_key); \ - return from_json(_MEOJSON_VARNAME(in), _MEOJSON_VARNAME(error_key)); \ - } \ - bool from_json(const json::value& _MEOJSON_VARNAME(in), std::string& _MEOJSON_VARNAME(error_key)) \ - { \ - return json::_jsonization_helper::loader()._from_json(_MEOJSON_VARNAME(in), _MEOJSON_VARNAME(error_key), \ - _MEOJSON_FOR_EACH(_MEOJSON_KEY_VALUE, __VA_ARGS__) \ - json::_jsonization_helper::va_arg_end {}); \ +#define MEO_FROMJSON(...) \ + bool from_json(const json::value& _MEOJSON_VARNAME(in)) \ + { \ + std::string _MEOJSON_VARNAME(error_key); \ + return from_json(_MEOJSON_VARNAME(in), _MEOJSON_VARNAME(error_key)); \ + } \ + bool from_json(const json::value& _MEOJSON_VARNAME(in), std::string& _MEOJSON_VARNAME(error_key)) \ + { \ + return json::_jsonization_helper::loader()._from_json( \ + _MEOJSON_VARNAME(in), _MEOJSON_VARNAME(error_key), \ + _MEOJSON_EXPAND(_MEOJSON_FOR_EACH(_MEOJSON_KEY_VALUE, __VA_ARGS__)) \ + json::_jsonization_helper::va_arg_end {}); \ } -// if you are using MSVC, please add "/Zc:preprocessor" to your project -#define MEO_JSONIZATION(...) MEO_TOJSON(__VA_ARGS__) MEO_CHECKJSON(__VA_ARGS__) MEO_FROMJSON(__VA_ARGS__) +#define MEO_JSONIZATION(...) \ + _MEOJSON_EXPAND(MEO_TOJSON(__VA_ARGS__)) \ + _MEOJSON_EXPAND(MEO_CHECKJSON(__VA_ARGS__)) \ + _MEOJSON_EXPAND(MEO_FROMJSON(__VA_ARGS__)) #define MEO_OPT json::_jsonization_helper::next_is_optional_t {}, diff --git a/test/serializing_test.cpp b/test/serializing_test.cpp index 4407215..7ec2b6a 100644 --- a/test/serializing_test.cpp +++ b/test/serializing_test.cpp @@ -204,20 +204,25 @@ bool jsonizing() struct MyStruct { - std::string str; + std::string str1; + std::string str2; + std::string str3; std::vector vec; std::unordered_map>>> map; - MEO_JSONIZATION(str, vec, map); + MEO_JSONIZATION(str1, str2, str3, vec, map); }; MyStruct mine; - mine.str = "Hello"; + mine.str1 = "Hello"; + mine.str2 = "World"; + mine.str3 = "!"; mine.vec.emplace_back(0.5); mine.map = { { "key_1", { { { "inner_key_1", { 7, 8, 9 } } }, { { "inner_key_2", { 10 } } } } } }; json::value j_mine = mine; MyStruct new_mine = (MyStruct)j_mine; - return new_third.a == 100 && new_mine.str == "Hello"; + return new_third.a == 100 && new_mine.str1 == "Hello" && new_mine.str2 == "World" && new_mine.str3 == "!" && + new_mine.vec[0] == 0.5 && new_mine.map["key_1"].size() == 2; }