@@ -44,19 +44,37 @@ public: \
44
44
Source<type> name; \
45
45
private:
46
46
47
- #define SINK (name, type ) \
47
+ /* We need to call the SinkBlocking<T>(size_t const size)
48
+ * non-default constructor using size as parameter.
49
+
50
+ * This is achieved via
51
+ * SinkBlocking<type> name{size};
52
+ * instead of
53
+ * SinkBlocking<type> name(size);
54
+ * otherwise the compiler will read it as a declaration
55
+ * of a method called "name" and we get a syntax error.
56
+ *
57
+ * This is called "C++11 uniform init" (using "{}" instead
58
+ * of "()" without "="... yikes!)
59
+ * https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++-dos-and-donts.md
60
+ */
61
+
62
+ #define SINK_2_ARG (name, type ) \
63
+ public: \
64
+ SinkBlocking<type> name{1 }; \
65
+ private:
66
+
67
+ #define SINK_3_ARG (name, type, size ) \
48
68
public: \
49
- SinkBlocking<type> name; \
69
+ SinkBlocking<type> name{size} ; \
50
70
private:
51
- // we need to call the Sink<T>(int size) non-default constructor using size as parameter.
52
- // This is done by writing
53
- // Sink<type> name{size};
54
- // instead of:
55
- // Sink<type> name(size);
56
- // otherwise the compiler will read it as a declaration of a method called "name" and we
57
- // get a syntax error.
58
- // This is called "C++11 uniform init" (using "{}" instead of "()" without "="... yikes!)
59
- // https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++-dos-and-donts.md
71
+
72
+ /* Black C macro magic enabling "macro overloading"
73
+ * with same name macro, but multiple arguments.
74
+ * https://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments
75
+ */
76
+ #define GET_SINK_MACRO (_1,_2,_3,NAME,...) NAME
77
+ #define SINK (...) GET_SINK_MACRO(__VA_ARGS__, SINK_3_ARG, SINK_2_ARG)(__VA_ARGS__)
60
78
61
79
#define SHARED (name, type ) \
62
80
Shared<type> name;
0 commit comments