Bumping manifests a=b2g-bump
[gecko.git] / mfbt / MacroForEach.h
blobae1f4d0e993cce52873dfb5b4995846ec9b58ff6
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * Implements a higher-order macro for iteratively calling another macro with
9 * fixed leading arguments, plus a trailing element picked from a second list
10 * of arguments.
13 #ifndef mozilla_MacroForEach_h
14 #define mozilla_MacroForEach_h
16 #include "mozilla/MacroArgs.h"
19 * MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) expands to N calls to the macro
20 * |aMacro| where N is equal the number of items in the list |aArgs|. The
21 * arguments for each |aMacro| call are composed of *all* arguments in the list
22 * |aFixedArgs| as well as a single argument in the list |aArgs|. For example:
24 * #define MACRO_A(x) x +
25 * int a = MOZ_FOR_EACH(MACRO_A, (), (1, 2, 3)) 0;
26 * // Expands to: MACRO_A(1) MACRO_A(2) MACRO_A(3) 0;
27 * // And further to: 1 + 2 + 3 + 0;
29 * #define MACRO_B(k, x) (k + x) +
30 * int b = MOZ_FOR_EACH(MACRO_B, (5,), (1, 2)) 0;
31 * // Expands to: MACRO_B(5, 1) MACRO_B(5, 2) 0;
33 * #define MACRO_C(k1, k2, x) (k1 + k2 + x) +
34 * int c = MOZ_FOR_EACH(MACRO_C, (5, 8,), (1, 2)) 0;
35 * // Expands to: MACRO_B(5, 8, 1) MACRO_B(5, 8, 2) 0;
37 * If the |aFixedArgs| list is not empty, a trailing comma must be included.
39 * The |aArgs| list must be not be empty and may be up to 50 items long. Use
40 * MOZ_STATIC_ASSERT_VALID_ARG_COUNT to ensure that violating this constraint
41 * results in a compile-time error.
43 #define MOZ_FOR_EACH_EXPAND_HELPER(...) __VA_ARGS__
44 #define MOZ_FOR_EACH_GLUE(a, b) a b
45 #define MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) \
46 MOZ_FOR_EACH_GLUE( \
47 MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_FOR_EACH_, \
48 MOZ_FOR_EACH_EXPAND_HELPER aArgs), \
49 (aMacro, aFixedArgs, aArgs))
51 #define MOZ_FOR_EACH_HELPER_GLUE(a, b) a b
52 #define MOZ_FOR_EACH_HELPER(aMacro, aFixedArgs, aArgs) \
53 MOZ_FOR_EACH_HELPER_GLUE( \
54 aMacro, \
55 (MOZ_FOR_EACH_EXPAND_HELPER aFixedArgs MOZ_ARG_1 aArgs))
57 #define MOZ_FOR_EACH_1(m, fa, a) \
58 MOZ_FOR_EACH_HELPER(m, fa, a)
59 #define MOZ_FOR_EACH_2(m, fa, a) \
60 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_1(m, fa, (MOZ_ARGS_AFTER_1 a))
61 #define MOZ_FOR_EACH_3(m, fa, a) \
62 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_2(m, fa, (MOZ_ARGS_AFTER_1 a))
63 #define MOZ_FOR_EACH_4(m, fa, a) \
64 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_3(m, fa, (MOZ_ARGS_AFTER_1 a))
65 #define MOZ_FOR_EACH_5(m, fa, a) \
66 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_4(m, fa, (MOZ_ARGS_AFTER_1 a))
67 #define MOZ_FOR_EACH_6(m, fa, a) \
68 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_5(m, fa, (MOZ_ARGS_AFTER_1 a))
69 #define MOZ_FOR_EACH_7(m, fa, a) \
70 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_6(m, fa, (MOZ_ARGS_AFTER_1 a))
71 #define MOZ_FOR_EACH_8(m, fa, a) \
72 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_7(m, fa, (MOZ_ARGS_AFTER_1 a))
73 #define MOZ_FOR_EACH_9(m, fa, a) \
74 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_8(m, fa, (MOZ_ARGS_AFTER_1 a))
75 #define MOZ_FOR_EACH_10(m, fa, a) \
76 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_9(m, fa, (MOZ_ARGS_AFTER_1 a))
77 #define MOZ_FOR_EACH_11(m, fa, a) \
78 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_10(m, fa, (MOZ_ARGS_AFTER_1 a))
79 #define MOZ_FOR_EACH_12(m, fa, a) \
80 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_11(m, fa, (MOZ_ARGS_AFTER_1 a))
81 #define MOZ_FOR_EACH_13(m, fa, a) \
82 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_12(m, fa, (MOZ_ARGS_AFTER_1 a))
83 #define MOZ_FOR_EACH_14(m, fa, a) \
84 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_13(m, fa, (MOZ_ARGS_AFTER_1 a))
85 #define MOZ_FOR_EACH_15(m, fa, a) \
86 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_14(m, fa, (MOZ_ARGS_AFTER_1 a))
87 #define MOZ_FOR_EACH_16(m, fa, a) \
88 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_15(m, fa, (MOZ_ARGS_AFTER_1 a))
89 #define MOZ_FOR_EACH_17(m, fa, a) \
90 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_16(m, fa, (MOZ_ARGS_AFTER_1 a))
91 #define MOZ_FOR_EACH_18(m, fa, a) \
92 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_17(m, fa, (MOZ_ARGS_AFTER_1 a))
93 #define MOZ_FOR_EACH_19(m, fa, a) \
94 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_18(m, fa, (MOZ_ARGS_AFTER_1 a))
95 #define MOZ_FOR_EACH_20(m, fa, a) \
96 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_19(m, fa, (MOZ_ARGS_AFTER_1 a))
97 #define MOZ_FOR_EACH_21(m, fa, a) \
98 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_20(m, fa, (MOZ_ARGS_AFTER_1 a))
99 #define MOZ_FOR_EACH_22(m, fa, a) \
100 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_21(m, fa, (MOZ_ARGS_AFTER_1 a))
101 #define MOZ_FOR_EACH_23(m, fa, a) \
102 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_22(m, fa, (MOZ_ARGS_AFTER_1 a))
103 #define MOZ_FOR_EACH_24(m, fa, a) \
104 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_23(m, fa, (MOZ_ARGS_AFTER_1 a))
105 #define MOZ_FOR_EACH_25(m, fa, a) \
106 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_24(m, fa, (MOZ_ARGS_AFTER_1 a))
107 #define MOZ_FOR_EACH_26(m, fa, a) \
108 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_25(m, fa, (MOZ_ARGS_AFTER_1 a))
109 #define MOZ_FOR_EACH_27(m, fa, a) \
110 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_26(m, fa, (MOZ_ARGS_AFTER_1 a))
111 #define MOZ_FOR_EACH_28(m, fa, a) \
112 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_27(m, fa, (MOZ_ARGS_AFTER_1 a))
113 #define MOZ_FOR_EACH_29(m, fa, a) \
114 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_28(m, fa, (MOZ_ARGS_AFTER_1 a))
115 #define MOZ_FOR_EACH_30(m, fa, a) \
116 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_29(m, fa, (MOZ_ARGS_AFTER_1 a))
117 #define MOZ_FOR_EACH_31(m, fa, a) \
118 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_30(m, fa, (MOZ_ARGS_AFTER_1 a))
119 #define MOZ_FOR_EACH_32(m, fa, a) \
120 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_31(m, fa, (MOZ_ARGS_AFTER_1 a))
121 #define MOZ_FOR_EACH_33(m, fa, a) \
122 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_32(m, fa, (MOZ_ARGS_AFTER_1 a))
123 #define MOZ_FOR_EACH_34(m, fa, a) \
124 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_33(m, fa, (MOZ_ARGS_AFTER_1 a))
125 #define MOZ_FOR_EACH_35(m, fa, a) \
126 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_34(m, fa, (MOZ_ARGS_AFTER_1 a))
127 #define MOZ_FOR_EACH_36(m, fa, a) \
128 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_35(m, fa, (MOZ_ARGS_AFTER_1 a))
129 #define MOZ_FOR_EACH_37(m, fa, a) \
130 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_36(m, fa, (MOZ_ARGS_AFTER_1 a))
131 #define MOZ_FOR_EACH_38(m, fa, a) \
132 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_37(m, fa, (MOZ_ARGS_AFTER_1 a))
133 #define MOZ_FOR_EACH_39(m, fa, a) \
134 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_38(m, fa, (MOZ_ARGS_AFTER_1 a))
135 #define MOZ_FOR_EACH_40(m, fa, a) \
136 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_39(m, fa, (MOZ_ARGS_AFTER_1 a))
137 #define MOZ_FOR_EACH_41(m, fa, a) \
138 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_40(m, fa, (MOZ_ARGS_AFTER_1 a))
139 #define MOZ_FOR_EACH_42(m, fa, a) \
140 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_41(m, fa, (MOZ_ARGS_AFTER_1 a))
141 #define MOZ_FOR_EACH_43(m, fa, a) \
142 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_42(m, fa, (MOZ_ARGS_AFTER_1 a))
143 #define MOZ_FOR_EACH_44(m, fa, a) \
144 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_43(m, fa, (MOZ_ARGS_AFTER_1 a))
145 #define MOZ_FOR_EACH_45(m, fa, a) \
146 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_44(m, fa, (MOZ_ARGS_AFTER_1 a))
147 #define MOZ_FOR_EACH_46(m, fa, a) \
148 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_45(m, fa, (MOZ_ARGS_AFTER_1 a))
149 #define MOZ_FOR_EACH_47(m, fa, a) \
150 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_46(m, fa, (MOZ_ARGS_AFTER_1 a))
151 #define MOZ_FOR_EACH_48(m, fa, a) \
152 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_47(m, fa, (MOZ_ARGS_AFTER_1 a))
153 #define MOZ_FOR_EACH_49(m, fa, a) \
154 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_48(m, fa, (MOZ_ARGS_AFTER_1 a))
155 #define MOZ_FOR_EACH_50(m, fa, a) \
156 MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_49(m, fa, (MOZ_ARGS_AFTER_1 a))
158 #endif /* mozilla_MacroForEach_h */