source: NonGTP/Boost/boost/pool/detail/for.m4 @ 857

Revision 857, 3.9 KB checked in by igarcia, 19 years ago (diff)
Line 
1m4_dnl
2m4_dnl Copyright (C) 2000 Stephen Cleary
3m4_dnl
4m4_dnl This file can be redistributed and/or modified under the terms found
5m4_dnl  in "copyright.html"
6m4_dnl This software and its documentation is provided "as is" without express or
7m4_dnl  implied warranty, and with no claim as to its suitability for any purpose.
8m4_dnl
9m4_dnl See http://www.boost.org for updates, documentation, and revision history.
10m4_dnl
11m4_dnl
12m4_dnl
13m4_dnl BOOST_M4_FOR: repeat a given text for a range of values
14m4_dnl   $1 - variable to hold the current value.
15m4_dnl   $2 - the starting value.
16m4_dnl   $3 - the ending value (text is _not_ repeated for this value).
17m4_dnl   $4 - the text to repeat.
18m4_dnl   $5 - the delimeter text (optional).
19m4_dnl
20m4_dnl If the starting value is < ending value:
21m4_dnl   Will repeat $4, binding $1 to the values in the range [$2, $3).
22m4_dnl Else (that is, starting value >= ending value):
23m4_dnl   Will do nothing
24m4_dnl Repeats $5 in-between each occurrence of $4
25m4_dnl
26m4_dnl Logic:
27m4_dnl   Set $1 to $2 and call BOOST_M4_FOR_LIST_HELPER:
28m4_dnl     If $1 >= $3, do nothing
29m4_dnl     Else
30m4_dnl       output $4,
31m4_dnl       set $1 to itself incremented,
32m4_dnl       If $1 != $3, output $5,
33m4_dnl       and use recursion
34m4_dnl
35m4_define(`BOOST_M4_FOR',
36          `m4_ifelse(m4_eval($# < 4 || $# > 5), 1,
37                     `m4_errprint(m4___file__:m4___line__: `Boost m4 script: BOOST_M4_FOR: Wrong number of arguments ($#)')',
38                     `m4_pushdef(`$1', `$2')BOOST_M4_FOR_HELPER($@)m4_popdef(`$1')')')m4_dnl
39m4_define(`BOOST_M4_FOR_HELPER',
40          `m4_ifelse(m4_eval($1 >= $3), 1, ,
41                     `$4`'m4_define(`$1', m4_incr($1))m4_ifelse(m4_eval($1 != $3), 1, `$5')`'BOOST_M4_FOR_HELPER($@)')')m4_dnl
42m4_dnl
43m4_dnl Testing/Examples:
44m4_dnl
45m4_dnl The following line will output:
46m4_dnl   "repeat.m4:42: Boost m4 script: BOOST_M4_FOR: Wrong number of arguments (3)"
47m4_dnl BOOST_M4_FOR(i, 1, 3)
48m4_dnl
49m4_dnl The following line will output:
50m4_dnl   "repeat.m4:46: Boost m4 script: BOOST_M4_FOR: Wrong number of arguments (6)"
51m4_dnl BOOST_M4_FOR(i, 1, 3, i, ` ', 13)
52m4_dnl
53m4_dnl The following line will output (nothing):
54m4_dnl   ""
55m4_dnl BOOST_M4_FOR(i, 7, 0, i )
56m4_dnl
57m4_dnl The following line will output (nothing):
58m4_dnl   ""
59m4_dnl BOOST_M4_FOR(i, 0, 0, i )
60m4_dnl
61m4_dnl The following line will output:
62m4_dnl   "0 1 2 3 4 5 6 "
63m4_dnl BOOST_M4_FOR(i, 0, 7, i )
64m4_dnl
65m4_dnl The following line will output:
66m4_dnl   "-13 -12 -11 "
67m4_dnl BOOST_M4_FOR(i, -13, -10, i )
68m4_dnl
69m4_dnl The following two lines will output:
70m4_dnl   "(0, 0) (0, 1) (0, 2) (0, 3) "
71m4_dnl   "(1, 0) (1, 1) (1, 2) (1, 3) "
72m4_dnl   "(2, 0) (2, 1) (2, 2) (2, 3) "
73m4_dnl   "(3, 0) (3, 1) (3, 2) (3, 3) "
74m4_dnl   "(4, 0) (4, 1) (4, 2) (4, 3) "
75m4_dnl   "(5, 0) (5, 1) (5, 2) (5, 3) "
76m4_dnl   "(6, 0) (6, 1) (6, 2) (6, 3) "
77m4_dnl   "(7, 0) (7, 1) (7, 2) (7, 3) "
78m4_dnl   ""
79m4_dnl BOOST_M4_FOR(i, 0, 8, BOOST_M4_FOR(j, 0, 4, (i, j) )
80m4_dnl )
81m4_dnl
82m4_dnl The following line will output (nothing):
83m4_dnl   ""
84m4_dnl BOOST_M4_FOR(i, 7, 0, i, |)
85m4_dnl
86m4_dnl The following line will output (nothing):
87m4_dnl   ""
88m4_dnl BOOST_M4_FOR(i, 0, 0, i, |)
89m4_dnl
90m4_dnl The following line will output:
91m4_dnl   "0|1|2|3|4|5|6"
92m4_dnl BOOST_M4_FOR(i, 0, 7, i, |)
93m4_dnl
94m4_dnl The following line will output:
95m4_dnl   "-13, -12, -11"
96m4_dnl BOOST_M4_FOR(i, -13, -10, i, `, ')
97m4_dnl
98m4_dnl The following two lines will output:
99m4_dnl   "[(0, 0), (0, 1), (0, 2), (0, 3)],"
100m4_dnl   "[(1, 0), (1, 1), (1, 2), (1, 3)],"
101m4_dnl   "[(2, 0), (2, 1), (2, 2), (2, 3)],"
102m4_dnl   "[(3, 0), (3, 1), (3, 2), (3, 3)],"
103m4_dnl   "[(4, 0), (4, 1), (4, 2), (4, 3)],"
104m4_dnl   "[(5, 0), (5, 1), (5, 2), (5, 3)],"
105m4_dnl   "[(6, 0), (6, 1), (6, 2), (6, 3)],"
106m4_dnl   "[(7, 0), (7, 1), (7, 2), (7, 3)]"
107m4_dnl BOOST_M4_FOR(i, 0, 8, `[BOOST_M4_FOR(j, 0, 4, (i, j), `, ')]', `,
108m4_dnl ')
109m4_dnl
Note: See TracBrowser for help on using the repository browser.