Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
name_value_pair_macro.hpp
Go to the documentation of this file.
1#pragma once
2
3/* start of #define NVP:
4 * expands to name-value pairs (NVPs), e.g. NVP(x,y,z) -> "x", x, "y", y", "z", z
5 * used in msgpack serialization. */
6
7// hacky counting of variadic macro params:
8#define VA_NARGS_IMPL(_1, \
9 _2, \
10 _3, \
11 _4, \
12 _5, \
13 _6, \
14 _7, \
15 _8, \
16 _9, \
17 _10, \
18 _11, \
19 _12, \
20 _13, \
21 _14, \
22 _15, \
23 _16, \
24 _17, \
25 _18, \
26 _19, \
27 _20, \
28 _21, \
29 _22, \
30 _23, \
31 _24, \
32 _25, \
33 _26, \
34 _27, \
35 _28, \
36 _29, \
37 _30, \
38 _31, \
39 _32, \
40 _33, \
41 _34, \
42 _35, \
43 _36, \
44 _37, \
45 _38, \
46 _39, \
47 _40, \
48 N, \
49 ...) \
50 N
51// AD: support for 40 fields!? one may ask. Well, after 30 not being enough...
52#define VA_NARGS(...) \
53 VA_NARGS_IMPL(__VA_ARGS__, \
54 40, \
55 39, \
56 38, \
57 37, \
58 36, \
59 35, \
60 34, \
61 33, \
62 32, \
63 31, \
64 30, \
65 29, \
66 28, \
67 27, \
68 26, \
69 25, \
70 24, \
71 23, \
72 22, \
73 21, \
74 20, \
75 19, \
76 18, \
77 17, \
78 16, \
79 15, \
80 14, \
81 13, \
82 12, \
83 11, \
84 10, \
85 9, \
86 8, \
87 7, \
88 6, \
89 5, \
90 4, \
91 3, \
92 2, \
93 1)
94
95// name-value pair expansion for variables
96// used in msgpack map expansion
97// n<=3 case
98#define _NVP1(x) #x, x
99#define _NVP2(x, y) #x, x, #y, y
100#define _NVP3(x, y, z) #x, x, #y, y, #z, z
101// n>3 cases
102#define _NVP4(x, ...) _NVP1(x), _NVP3(__VA_ARGS__)
103#define _NVP5(x, ...) _NVP1(x), _NVP4(__VA_ARGS__)
104#define _NVP6(x, ...) _NVP1(x), _NVP5(__VA_ARGS__)
105#define _NVP7(x, ...) _NVP1(x), _NVP6(__VA_ARGS__)
106#define _NVP8(x, ...) _NVP1(x), _NVP7(__VA_ARGS__)
107#define _NVP9(x, ...) _NVP1(x), _NVP8(__VA_ARGS__)
108#define _NVP10(x, ...) _NVP1(x), _NVP9(__VA_ARGS__)
109#define _NVP11(x, ...) _NVP1(x), _NVP10(__VA_ARGS__)
110#define _NVP12(x, ...) _NVP1(x), _NVP11(__VA_ARGS__)
111#define _NVP13(x, ...) _NVP1(x), _NVP12(__VA_ARGS__)
112#define _NVP14(x, ...) _NVP1(x), _NVP13(__VA_ARGS__)
113#define _NVP15(x, ...) _NVP1(x), _NVP14(__VA_ARGS__)
114#define _NVP16(x, ...) _NVP1(x), _NVP15(__VA_ARGS__)
115#define _NVP17(x, ...) _NVP1(x), _NVP16(__VA_ARGS__)
116#define _NVP18(x, ...) _NVP1(x), _NVP17(__VA_ARGS__)
117#define _NVP19(x, ...) _NVP1(x), _NVP18(__VA_ARGS__)
118#define _NVP20(x, ...) _NVP1(x), _NVP19(__VA_ARGS__)
119#define _NVP21(x, ...) _NVP1(x), _NVP20(__VA_ARGS__)
120#define _NVP22(x, ...) _NVP1(x), _NVP21(__VA_ARGS__)
121#define _NVP23(x, ...) _NVP1(x), _NVP22(__VA_ARGS__)
122#define _NVP24(x, ...) _NVP1(x), _NVP23(__VA_ARGS__)
123#define _NVP25(x, ...) _NVP1(x), _NVP24(__VA_ARGS__)
124#define _NVP26(x, ...) _NVP1(x), _NVP25(__VA_ARGS__)
125#define _NVP27(x, ...) _NVP1(x), _NVP26(__VA_ARGS__)
126#define _NVP28(x, ...) _NVP1(x), _NVP27(__VA_ARGS__)
127#define _NVP29(x, ...) _NVP1(x), _NVP28(__VA_ARGS__)
128#define _NVP30(x, ...) _NVP1(x), _NVP29(__VA_ARGS__)
129#define _NVP31(x, ...) _NVP1(x), _NVP30(__VA_ARGS__)
130#define _NVP32(x, ...) _NVP1(x), _NVP31(__VA_ARGS__)
131#define _NVP33(x, ...) _NVP1(x), _NVP32(__VA_ARGS__)
132#define _NVP34(x, ...) _NVP1(x), _NVP33(__VA_ARGS__)
133#define _NVP35(x, ...) _NVP1(x), _NVP34(__VA_ARGS__)
134#define _NVP36(x, ...) _NVP1(x), _NVP35(__VA_ARGS__)
135#define _NVP37(x, ...) _NVP1(x), _NVP36(__VA_ARGS__)
136#define _NVP38(x, ...) _NVP1(x), _NVP37(__VA_ARGS__)
137#define _NVP39(x, ...) _NVP1(x), _NVP38(__VA_ARGS__)
138#define _NVP40(x, ...) _NVP1(x), _NVP39(__VA_ARGS__)
139
140#define CONCAT(a, b) a##b
141#define _NVP_N(n) CONCAT(_NVP, n)
142#define NVP(...) _NVP_N(VA_NARGS(__VA_ARGS__))(__VA_ARGS__)
143// end of #define NVP