detail/for.m4 provides BOOST_M4_FOR, an m4 macro that provides the equivalent of a #for preprocessor instruction.
This macro must be used by an m4 file. This file assumes that the option -P is used, to force an m4_ prefix on all builtin symbols.
If called with the wrong number of arguments (less than 4 or more than 5), BOOST_M4_FOR will exit with an error. If the starting value ($2) is greater than or equal to the ending value ($3), BOOST_M4_FOR will do nothing. Otherwise, it will repeat the text ($4), binding the variable ($1) to the values in the range [starting value ($2), ending value ($3)), and repeat the delimeter text ($5) in-between each occurrence of the repeat text ($4).
Note of the quotation marks (") used in the table below are in the input or output; they are shown to delimit whitespace. All code within a pair of quotation marks is intended to be on one line.
Input | Output |
---|---|
"BOOST_M4_FOR(i, 1, 3)" | Boost m4 script: BOOST_M4_FOR: Wrong number of arguments (3) |
"BOOST_M4_FOR(i, 1, 3, i, ` ', 13)" | Boost m4 script: BOOST_M4_FOR: Wrong number of arguments (6) |
"BOOST_M4_FOR(i, 7, 0, i )" | (nothing) |
"BOOST_M4_FOR(i, 0, 0, i )" | (nothing) |
"BOOST_M4_FOR(i, 0, 7, i )" | "0 1 2 3 4 5 6 " |
"BOOST_M4_FOR(i, -13, -10, i )" | "-13 -12 -11 " |
"BOOST_M4_FOR(i, 0, 8, BOOST_M4_FOR(j, 0, 4, (i, j) )" ")" | "(0, 0) (0, 1) (0, 2) (0, 3) " "(1, 0) (1, 1) (1, 2) (1, 3) " "(2, 0) (2, 1) (2, 2) (2, 3) " "(3, 0) (3, 1) (3, 2) (3, 3) " "(4, 0) (4, 1) (4, 2) (4, 3) " "(5, 0) (5, 1) (5, 2) (5, 3) " "(6, 0) (6, 1) (6, 2) (6, 3) " "(7, 0) (7, 1) (7, 2) (7, 3) " "" |
"BOOST_M4_FOR(i, 7, 0, i, |)" | (nothing) |
"BOOST_M4_FOR(i, 0, 0, i, |)" | (nothing) |
"BOOST_M4_FOR(i, 0, 7, i, |)" | "0|1|2|3|4|5|6" |
"BOOST_M4_FOR(i, -13, -10, i, `, ')" | "-13, -12, -11" |
"BOOST_M4_FOR(i, 0, 8, `[BOOST_M4_FOR(j, 0, 4, (i, j), `, ')]', `," "')" | "[(0, 0), (0, 1), (0, 2), (0, 3)]," "[(1, 0), (1, 1), (1, 2), (1, 3)]," "[(2, 0), (2, 1), (2, 2), (2, 3)]," "[(3, 0), (3, 1), (3, 2), (3, 3)]," "[(4, 0), (4, 1), (4, 2), (4, 3)]," "[(5, 0), (5, 1), (5, 2), (5, 3)]," "[(6, 0), (6, 1), (6, 2), (6, 3)]," "[(7, 0), (7, 1), (7, 2), (7, 3)]" |
Copyright © 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT com)
This file can be redistributed and/or modified under the terms found in copyright.html
This software and its documentation is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.