Go to the documentation of this file.
26 #ifndef CARGO_FIELDS_HPP
27 #define CARGO_FIELDS_HPP
29 #include <boost/preprocessor/variadic/to_list.hpp>
30 #include <boost/preprocessor/list/for_each.hpp>
34 #if BOOST_PP_VARIADICS != 1
35 #error variadic macros not supported
42 #define CARGO_REGISTER_EMPTY \
43 template<typename Visitor> \
44 static void accept(Visitor ) { \
74 #define CARGO_REGISTER(...) \
75 template<typename Visitor> \
76 void accept(Visitor v) { \
77 GENERATE_ELEMENTS__(__VA_ARGS__) \
79 template<typename Visitor> \
80 void accept(Visitor v) const { \
81 GENERATE_ELEMENTS__(__VA_ARGS__) \
125 #define CARGO_EXTEND(BASE) \
126 typedef BASE ParentVisitor; \
129 #define __CARGO_EXTEND(...) \
130 template<typename Visitor> \
131 void accept(Visitor v) { \
132 GENERATE_ELEMENTS__(__VA_ARGS__) \
133 ParentVisitor::accept(v); \
135 template<typename Visitor> \
136 void accept(Visitor v) const { \
137 GENERATE_ELEMENTS__(__VA_ARGS__) \
138 ParentVisitor::accept(v); \
141 #define GENERATE_ELEMENTS__(...) \
142 BOOST_PP_LIST_FOR_EACH(GENERATE_ELEMENT__, \
144 BOOST_PP_VARIADIC_TO_LIST(__VA_ARGS__)) \
146 #define GENERATE_ELEMENT__(r, _, element) \
147 v.visit(#element, element); \
149 #endif // CARGO_FIELDS_HPP