how are the iterative/looping mechanism implemented in boost preprocessor?
at first i thought that the boost library came with it's own implementation of a c preprocessor, as i thought that was the only way it could be doing all that iteration (multiple "patterned" declarations, etc, etc) and the c standard hasn't introduced a notion of counters... i've considered concatenation, but that incurs a "final" string to be compared which cannot be generated automatically a priori (correct me if i'm mistaken). but when i looked at boost thoroughly, it seems to be doing everything in standard. so can anybody tell me how that is done? a sort of pseudo-code for doing this will be very helpful: #define MULTIPLE_ENUMS(my_enum, n) /* ^ will declare n enumerations using prefix "my_enum" and having concatenated 0 to n each. optional: having ALL the minimum value of each enum be 0 (easy) and maximum values for each multiplied by a magnitude of 2 starting from an initial value (which then becomes): #define MULTIPLE_ENUMS(my_enum, init, 5) */ i know this may sound trivial and totally beginner-like, but can anyone explain it to me, as i don't have the whole day just trying to decipher everything out.
The C++ preprocessor expands macros ***recursively***.
Recursion is the secret. This is also how functional languages (eg. Haskell)
implement iteration without having looping control structures like "for" or
"while".
On Tue, May 24, 2011 at 3:20 PM, R A
at first i thought that the boost library came with it's own implementation of a c preprocessor, as i thought that was the only way it could be doing all that iteration (multiple "patterned" declarations, etc, etc) and the c standard hasn't introduced a notion of counters... i've considered concatenation, but that incurs a "final" string to be compared which cannot be generated automatically a priori (correct me if i'm mistaken). but when i looked at boost thoroughly, it seems to be doing everything in standard. so can anybody tell me how that is done?
AMDG On 05/24/2011 02:54 PM, Marc Poulin wrote:
The C++ preprocessor expands macros ***recursively***.
Recursion is the secret. This is also how functional languages (eg. Haskell) implement iteration without having looping control structures like "for" or "while".
Actually the preprocessor doesn't support recursion. In Christ, Steven Watanabe
On 05/24/2011 02:20 PM, R A wrote:
at first i thought that the boost library came with it's own implementation of a c preprocessor, as i thought that was the only way it could be doing all that iteration (multiple "patterned" declarations, etc, etc) and the c standard hasn't introduced a notion of counters... i've considered concatenation, but that incurs a "final" string to be compared which cannot be generated automatically a priori (correct me if i'm mistaken). but when i looked at boost thoroughly, it seems to be doing everything in standard. so can anybody tell me how that is done?
<snip>
i know this may sound trivial and totally beginner-like, but can anyone explain it to me, as i don't have the whole day just trying to decipher everything out.
A little time with the Boost.Preprocessor library documentation should get you going. http://www.boost.org/doc/libs/1_46_1/libs/preprocessor/doc/index.html -- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com
R A : Look at the documentation for the *BOOST_PP_SEQ_FOR_EACH* macro. The example on that page does exactly what your pseudo-code is trying to do. On Tue, May 24, 2011 at 4:11 PM, Michael Caisse < boost@objectmodelingdesigns.com> wrote:
A little time with the Boost.Preprocessor library documentation should get you going.
http://www.boost.org/doc/libs/1_46_1/libs/preprocessor/doc/index.html
participants (4)
-
Marc Poulin
-
Michael Caisse
-
R A
-
Steven Watanabe