boost_preprocessor 0.1.0

Boost C++ library boost_preprocessor packaged using Zanbil
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html

  lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
    <meta name="generator" content="Docutils 0.3.8: http://docutils.sourceforge.net/" />
    <title>Appendix A - An Introduction to Preprocessor Metaprogramming</title>
    <meta name="copyright" content="From &quot;C++ Template Metaprogramming,&quot; by David Abrahams and Aleksey Gurtovoy.  Copyright (c) 2005 by Pearson Education, Inc. Reprinted with permission." />
    <style type="text/css">

/*
:Author: David Goodger
:Contact: goodger@users.sourceforge.net
:date: $Date: 2004/06/23 13:31:26 $
:version: $Revision: 1.37 $
:copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
*/

.first {
  margin-top: 0 }

.last {
  margin-bottom: 0 }

a.toc-backref {
  text-decoration: none ;
  color: black }

blockquote.epigraph {
  margin: 2em 5em ; }

dd {
  margin-bottom: 0.5em }

/* Uncomment (and remove this text!) to get bold-faced definition list terms
dt {
  font-weight: bold }
*/

div.abstract {
  margin: 2em 5em }

div.abstract p.topic-title {
  font-weight: bold ;
  text-align: center }

div.attention, div.caution, div.danger, div.error, div.hint,
div.important, div.note, div.tip, div.warning, div.admonition {
  margin: 2em ;
  border: medium outset ;
  padding: 1em }

div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
  color: red ;
  font-weight: bold ;
  font-family: sans-serif }

div.hint p.admonition-title, div.important p.admonition-title,
div.note p.admonition-title, div.tip p.admonition-title,
div.admonition p.admonition-title {
  font-weight: bold ;
  font-family: sans-serif }

div.dedication {
  margin: 2em 5em ;
  text-align: center ;
  font-style: italic }

div.dedication p.topic-title {
  font-weight: bold ;
  font-style: normal }

div.figure {
  margin-left: 2em }

div.footer, div.header {
  font-size: smaller }

div.sidebar {
  margin-left: 1em ;
  border: medium outset ;
  padding: 0em 1em ;
  background-color: #ffffee ;
  width: 40% ;
  float: right ;
  clear: right }

div.sidebar p.rubric {
  font-family: sans-serif ;
  font-size: medium }

div.system-messages {
  margin: 5em }

div.system-messages h1 {
  color: red }

div.system-message {
  border: medium outset ;
  padding: 1em }

div.system-message p.system-message-title {
  color: red ;
  font-weight: bold }

div.topic {
  margin: 2em }

h1.title {
  text-align: center }

h2.subtitle {
  text-align: center }

hr {
  width: 75% }

ol.simple, ul.simple {
  margin-bottom: 1em }

ol.arabic {
  list-style: decimal }

ol.loweralpha {
  list-style: lower-alpha }

ol.upperalpha {
  list-style: upper-alpha }

ol.lowerroman {
  list-style: lower-roman }

ol.upperroman {
  list-style: upper-roman }

p.attribution {
  text-align: right ;
  margin-left: 50% }

p.caption {
  font-style: italic }

p.credits {
  font-style: italic ;
  font-size: smaller }

p.label {
  white-space: nowrap }

p.rubric {
  font-weight: bold ;
  font-size: larger ;
  color: maroon ;
  text-align: center }

p.sidebar-title {
  font-family: sans-serif ;
  font-weight: bold ;
  font-size: larger }

p.sidebar-subtitle {
  font-family: sans-serif ;
  font-weight: bold }

p.topic-title {
  font-weight: bold }

pre.address {
  margin-bottom: 0 ;
  margin-top: 0 ;
  font-family: serif ;
  font-size: 100% }

pre.line-block {
  font-family: serif ;
  font-size: 100% }

pre.literal-block, pre.doctest-block {
  margin-left: 2em ;
  margin-right: 2em ;
  background-color: #eeeeee }

span.classifier {
  font-family: sans-serif ;
  font-style: oblique }

span.classifier-delimiter {
  font-family: sans-serif ;
  font-weight: bold }

span.interpreted {
  font-family: sans-serif }

span.option {
  white-space: nowrap }

span.option-argument {
  font-style: italic }

span.pre {
  white-space: pre }

span.problematic {
  color: red }

table {
  margin-top: 0.5em ;
  margin-bottom: 0.5em }

table.citation {
  border-left: solid thin gray ;
  padding-left: 0.5ex }

table.docinfo {
  margin: 2em 4em }

table.footnote {
  border-left: solid thin black ;
  padding-left: 0.5ex }

dt {
  font-weight: bold }

td, th {
  padding-left: 0.5em ;
  padding-right: 0.5em ;
  vertical-align: top }

th.docinfo-name, th.field-name {
  font-weight: bold ;
  text-align: left ;
  white-space: nowrap }

h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt {
  font-size: 100% }

tt {
  background-color: #eeeeee }

ul.auto-toc {
  list-style-type: none }

</style> </head>
  <body><br />
    <div class="document" id="preprocessor-title">
      <h1 class="title">Appendix A - An Introduction to Preprocessor
        Metaprogramming</h1>
      <table class="docinfo" frame="void" rules="none">
        <colgroup><col class="docinfo-name" /> <col class="docinfo-content" />
        </colgroup>
        <tbody valign="top">
          <tr>
            <th class="docinfo-name">Copyright:</th>
            <td>From "C++ Template Metaprogramming," by David Abrahams and
              Aleksey Gurtovoy. Copyright (c) 2005 by Pearson Education, Inc.
              Reprinted with permission.</td>
          </tr>
          <tr class="field">
            <th class="docinfo-name">ISBN:</th>
            <td class="field-body">0321227255</td>
          </tr>
        </tbody>
      </table>
      <div class="section" id="motivation">
        <h1><a name="motivation">A.1   Motivation</a></h1>
        <p>Even with the full power of template metaprogramming and the <a class="reference"

            href="http://www.boost.org/libs/mpl">Boost Metaprogramming library</a>
          at our disposal, some C++ coding jobs still require a great deal of
          boilerplate code repetition. We saw one example in Chapter 5, when we
          implemented <tt class="docutils literal"><span class="pre">tiny_size</span></tt>:</p>
        <pre class="literal-block">template &lt;class T0, class T1, class T2&gt;
struct tiny_size
  : mpl::int_&lt;3&gt; {};
</pre>
        <!-- : rst-mode hack -->
        <!-- @prefix.append('struct none {};') -->
        <p>Aside from the repeated pattern in the parameter list of the primary
          template above, there are three partial specializations below, which
          also follow a predictable pattern:</p>
        <pre class="literal-block">template &lt;class T0, class T1&gt;
struct tiny_size&lt;T0,T1,none&gt;
  : mpl::int_&lt;2&gt; {};

template &lt;class T0&gt;
struct tiny_size&lt;T0,none,none&gt;
  : mpl::int_&lt;1&gt; {};

template &lt;&gt;
struct tiny_size&lt;none,none,none&gt;
  : mpl::int_&lt;0&gt; {};
</pre>
        <!-- : rst-mode hack -->
        <!-- @compile('all') -->
        <p>In this case there is only a small amount of code with such a
          "mechanical" flavor, but had we been implementing <tt class="docutils literal"><span

              class="pre">large</span></tt> instead of <tt class="docutils literal"><span

              class="pre">tiny</span></tt>, there might easily have been a great
          deal more. When the number of instances of a pattern grows beyond two
          or three, writing them by hand tends to become error-prone. Perhaps
          more importantly, the code gets hard to read, because the important
          abstraction in the code is really the pattern, not the individual
          instances.</p>
        <div class="section" id="code-generation">
          <h2><a name="code-generation">A.1.1   Code Generation</a></h2>
          <p>Rather than being written out by hand, mechanical-looking code
            should really be generated mechanically. Having written a program to
            spit out instances of the code pattern, a library author has two
            choices: She can either ship pre-generated source code files, or she
            can ship the generator itself. Either approach has drawbacks. If
            clients only get the generated source, they are stuck with whatever
            the library author generated—and experience shows that if they are
            happy with three instances of a pattern today, someone will need
            four tomorrow. If clients get the generator program, on the other
            hand, they also need the resources to execute it (e.g.,
            interpreters), and they must integrate the generator into their
            build processes...</p>
        </div>
        <div class="section" id="enter-the-preprocessor">
          <h2><a name="enter-the-preprocessor">A.1.2   Enter the Preprocessor</a></h2>
          <p>...unless the generator is a preprocessor metaprogram. Though not
            designed for that purpose, the C and C++ preprocessors can be made
            to execute sophisticated programs during the preprocessing phase of
            compilation. Users can control the code generation process with
            preprocessor <tt class="docutils literal"><span class="pre">#define</span></tt>s
            in code or <tt class="docutils literal"><span class="pre">-D</span></tt>
            options on the compiler's command line, making build integration
            trivial. For example, we might parameterize the primary <tt class="docutils literal"><span

                class="pre">tiny_size</span></tt> template above as follows:</p>
          <pre class="literal-block">#include &lt;<strong>boost/preprocessor/repetition/enum_params</strong>.hpp&gt;

#ifndef TINY_MAX_SIZE
#  define TINY_MAX_SIZE 3  // default maximum size is 3
#endif

template &lt;<strong>BOOST_PP_ENUM_PARAMS(TINY_MAX_SIZE, class T)</strong>&gt;
struct tiny_size
  : mpl::int_&lt;TINY_MAX_SIZE&gt;
{};
</pre>
          <!-- : rst-mode hack -->
          <!-- @compile(pop = None) -->
          <p>To test the metaprogram, run your compiler in its "preprocessing"
            mode (usually the <tt class="docutils literal"><span class="pre">-E</span></tt>
            option), with the Boost root directory in your <tt class="docutils literal"><span

                class="pre">#include</span></tt> path. For instance:<a class="footnote-reference"

              href="#minusp" id="id2" name="id2">[1]</a></p>
          <pre class="literal-block">g++ -P -E -Ipath/to/boost_1_32_0 -I. test.cpp
</pre>
          <!-- @ignore() -->
          <table class="docutils footnote" frame="void" id="minusp" rules="none">
            <colgroup><col class="label" /><col /></colgroup>
            <tbody valign="top">
              <tr>
                <td class="label"><a class="fn-backref" href="#id2" name="minusp">[1]</a></td>
                <td>GCC's <tt class="docutils literal"><span class="pre">-P</span></tt>
                  option inhibits the generation of source file and line number
                  markers in preprocessed output.</td>
              </tr>
            </tbody>
          </table>
          <p>Given the appropriate metaprograms, users would be able to adjust
            not only the number of parameters to <tt class="docutils literal"><span

                class="pre">tiny_size</span></tt>, but the maximum size of the
            entire <tt class="docutils literal"><span class="pre">tiny</span></tt>
            implementation just by <tt class="docutils literal"><span class="pre">#define</span></tt>-ing
            <tt class="docutils literal"><span class="pre">TINY_MAX_SIZE</span></tt>.</p>
          <p>The Boost Preprocessor library <a class="citation-reference" href="#mk04"

              id="id3" name="id3">[MK04]</a> plays a role in preprocessor
            metaprogramming similar to the one played by the MPL in template
            metaprogramming: It supplies a framework of high-level components
            (like <tt class="docutils literal"><span class="pre">BOOST_PP_ENUM_PARAMS</span></tt>)
            that make otherwise-painful metaprogramming jobs approachable. In
            this appendix we won't attempt to cover nitty-gritty details of how
            the preprocessor works, nor principles of preprocessor
            metaprogramming in general, nor even many details of how the
            Preprocessor <em>library</em> works. We <em>will</em> show you
            enough at a high level that you'll be able to use the library
            productively and learn the rest on your own.</p>
          <table class="docutils citation" frame="void" id="mk04" rules="none">
            <colgroup><col class="label" /><col /></colgroup>
            <tbody valign="top">
              <tr>
                <td class="label"><a class="fn-backref" href="#id3" name="mk04">[MK04]</a></td>
                <td>Paul Mensonides and Vesa Karvonen. "The Boost Preprocessor
                  Library." <a class="reference" href="http://www.boost.org/libs/preprocessor">http://www.boost.org/libs/preprocessor</a>.</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <div class="section" id="fundamental-abstractions-of-the-preprocessor">
        <h1><a name="fundamental-abstractions-of-the-preprocessor">A.2   Fundamental
            Abstractions of the Preprocessor</a></h1>
        <p>We began our discussion of template metaprogramming in Chapter 2 by
          describing its metadata (potential template arguments) and
          metafunctions (class templates). On the basis of those two fundamental
          abstractions, we built up the entire picture of compile-time
          computation covered in the rest of this book. In this section we'll
          lay a similar foundation for the preprocessor metaprogrammer. Some of
          what we cover here may be a review for you, but it's important to
          identify the basic concepts going into detail.</p>
        <div class="section" id="preprocessing-tokens">
          <h2><a name="preprocessing-tokens">A.2.1   Preprocessing Tokens</a></h2>
          <p>The fundamental unit of data in the preprocessor is the <strong>preprocessing
              token</strong>. Preprocessing tokens correspond roughly to the
            tokens you're used to working with in C++, such as identifiers,
            operator symbols, and literals. Technically, there are some
            differences between <em>preprocessing tokens</em> and regular <em>tokens</em>
            (see section 2 of the C++ standard for details), but they can be
            ignored for the purposes of this discussion. In fact, we'll be using
            the terms interchangeably here.</p>
        </div>
        <div class="section" id="macros">
          <h2><a name="macros">A.2.2   Macros</a></h2>
          <p>Preprocessor macros come in two flavors. <strong>Object-like
              macros</strong> can be defined this way:</p>
          <blockquote>
            <div class="line-block">
              <div class="line"><tt class="docutils literal"><span class="pre">#define</span></tt>
                <em>identifier</em> <em>replacement-list</em></div>
            </div>
          </blockquote>
          <!-- @litre_translator.line_offset -= 7 -->
          <p>where the <em>identifier</em> names the macro being defined, and <em>replacement-list</em>
            is a sequence of zero or more tokens. Where the <em>identifier</em>
            appears in subsequent program text, it is <strong>expanded</strong>
            by the preprocessor into its <em>replacement-list</em>.</p>
          <p><strong>Function-like macros</strong>, which act as the
            "metafunctions of the preprocessing phase," are defined as follows:</p>
          <blockquote>
            <div class="line-block">
              <div class="line"><tt class="docutils literal"><span class="pre">#define</span></tt>
                <em>identifier</em>(<em>a</em><sub>1</sub>, <em>a</em><sub>2</sub>,
                ... <em>a</em><sub>n</sub>) <em>replacement-list</em></div>
            </div>
          </blockquote>
          <!-- @litre_translator.line_offset -= 7 -->
          <p>where each <em>a</em><sub>i</sub> is an identifier naming a <strong>macro
              parameter</strong>. When the macro name appears in subsequent
            program text followed by a suitable argument list, it is expanded
            into its <em>replacement-list</em>, except that each argument is
            substituted for the corresponding parameter where it appears in the
            <em>replacement-list</em>.<a class="footnote-reference" href="#expansion"

              id="id4" name="id4">[2]</a></p>
          <table class="docutils footnote" frame="void" id="expansion" rules="none">
            <colgroup><col class="label" /><col /></colgroup>
            <tbody valign="top">
              <tr>
                <td class="label"><a class="fn-backref" href="#id4" name="expansion">[2]</a></td>
                <td>We have omitted many details of how macro expansion works.
                  We encourage you to take a few minutes to study section 16.3
                  of the C++ standard, which describes that process in
                  straightforward terms.</td>
              </tr>
            </tbody>
          </table>
        </div>
        <div class="section" id="macro-arguments">
          <h2><a name="macro-arguments">A.2.3   Macro Arguments</a></h2>
          <div class="admonition-definition admonition">
            <p class="first admonition-title">Definition</p>
            <p>A <strong>macro argument</strong> is a nonempty sequence of:</p>
            <ul class="last simple">
              <li>Preprocessing tokens other than commas or parentheses, <em>and/or</em></li>
              <li>Preprocessing tokens surrounded by matched pairs of
                parentheses.</li>
            </ul>
          </div>
          <p>This definition has consequences for preprocessor metaprogramming
            that must not be underestimated. Note, first of all, that the
            following tokens have special status:</p>
          <blockquote>
            <pre class="literal-block">,  (  )
</pre> </blockquote>
          <!-- @ignore() -->
          <p>As a result, a macro argument can never contain an unmatched
            parenthesis, or a comma that is not surrounded by matched
            parentheses. For example, both lines following the definition of FOO
            below are ill-formed:</p>
          <pre class="literal-block">#define FOO(X) X // Unary identity macro
FOO(,)           // un-parenthesized comma or two empty arguments
FOO())           // unmatched parenthesis or missing argument
</pre>
          <!-- @def pp_failure(options = ['-E'], **kw):
    compile(        expect_error = not 'mwcc' in config.compiler      , options = options, **kw)pp_failure() -->
          <p>Note also that the following tokens do <em>not</em> have special
            status; the preprocessor knows nothing about matched pairs of
            braces, brackets, or angle brackets:</p>
          <blockquote>
            <pre class="literal-block">{  }  [  ]  &lt;  &gt;
</pre> </blockquote>
          <!-- @ignore() -->
          <p>As a result, these lines are also ill-formed:</p>
          <pre class="literal-block">FOO(std::pair&lt;int<strong>,</strong> long&gt;)                // two arguments
FOO({ int x = 1<strong>,</strong> y = 2; return x+y; })   // two arguments
</pre>
          <!-- @example.prepend('#define FOO(X) X')
pp_failure() -->
          <p>It <em>is</em> possible to pass either string of tokens above as
            part of a single macro argument, provided it is parenthesized:</p>
          <pre class="literal-block">FOO(<strong>(</strong>std::pair&lt;int,int&gt;<strong>)</strong>)                 // one argument
FOO(<strong>(</strong>{ int x = 1, y = 2; return x+y; }<strong>)</strong>)  // one argument
</pre>
          <!-- @example.prepend('#define FOO(X) X')
compile(options = ['-E']) -->
          <p>However, because of the special status of commas, it is impossible
            to strip parentheses from a macro argument without knowing the
            number of comma-separated token sequences it contains.<a class="footnote-reference"

              href="#c99" id="id5" name="id5">[3]</a> If you are writing a macro
            that needs to be able to accept an argument containing a variable
            number of commas, your users will either have to parenthesize that
            argument <em>and</em> pass you the number of comma-separated token
            sequences as an additional argument, or they will have to encode the
            same information in one of the preprocessor data structures covered
            later in this appendix.</p>
          <table class="docutils footnote" frame="void" id="c99" rules="none">
            <colgroup><col class="label" /><col /></colgroup>
            <tbody valign="top">
              <tr>
                <td class="label"><a name="c99">[3]</a></td>
                <td><em>(<a class="fn-backref" href="#id5">1</a>, <a class="fn-backref"

                      href="#id12">2</a>)</em> The C99 preprocessor, by virtue
                  of its variadic macros, can do that and more. The C++
                  standardization committee is likely to adopt C99's
                  preprocessor extensions for the next version of the C++
                  standard.</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <div class="section" id="preprocessor-library-structure">
        <h1><a name="preprocessor-library-structure">A.3   Preprocessor Library
            Structure</a></h1>
        <p>Since in-depth coverage of the Boost Preprocessor library is beyond
          the scope of this book, we'll try to give you the <em>tools</em> to
          gain an in-depth understanding of the library here. To do that, you'll
          need to use the electronic Preprocessor library documentation, which
          begins with the index.html file in the <tt class="docutils literal"><span

              class="pre">libs/preprocessor/</span></tt> subdirectory of your
          Boost installation.</p>
        <p>On the left of your browser window you'll see an index, and if you
          follow the "Headers" link, it will reveal the structure of the <tt class="docutils literal"><span

              class="pre">boost/preprocessor/</span></tt> directory. Most of the
          library's headers are grouped into subdirectories according to related
          functionality. The top-level directory contains only a few headers
          that provide general-purpose macros, along with a header for each
          subdirectory that simply <tt class="docutils literal"><span class="pre">#include</span></tt>s
          all the headers in that subdirectory. For example, <tt class="docutils literal"><span

              class="pre">boost/preprocessor/selection.hpp</span></tt> does
          nothing more than to <tt class="docutils literal"><span class="pre">#include</span></tt>
          the <tt class="docutils literal"><span class="pre">min.hpp</span></tt>
          and <tt class="docutils literal"><span class="pre">max.hpp</span></tt>
          headers that comprise the contents of <tt class="docutils literal"><span

              class="pre">boost/preprocessor/selection/</span></tt>. The headers
          whose names <em>don't</em> correspond to subdirectories generally
          declare a macro whose name is the same as the name of the header,
          without the extension, and with a <tt class="docutils literal"><span

              class="pre">BOOST_PP_</span></tt> prefix. For example, <tt class="docutils literal"><span

              class="pre">boost/preprocessor/selection/max.hpp</span></tt>
          declares <tt class="docutils literal"><span class="pre">BOOST_PP_MAX</span></tt>.</p>
        <p>You'll also notice that often a header will declare an additional
          macro with a <tt class="docutils literal"><span class="pre">_D</span></tt>,
          <tt class="docutils literal"><span class="pre">_R</span></tt>, or <tt

            class="docutils literal"><span class="pre">_Z</span></tt> suffix.<a

            class="footnote-reference" href="#suffix" id="id6" name="id6">[4]</a>
          For instance, <tt class="docutils literal"><span class="pre">boost/preprocessor/selection/max.hpp</span></tt>
          also declares <tt class="docutils literal"><span class="pre">BOOST_PP_MAX_D</span></tt>.
          For the purposes of this appendix, you should ignore those macros.
          Eventually you will want to understand how they can be used to
          optimize preprocessing speed; consult the Topics section of the
          library documentation under the subheading "reentrancy" for that
          information.</p>
        <table class="docutils footnote" frame="void" id="suffix" rules="none">
          <colgroup><col class="label" /><col /></colgroup>
          <tbody valign="top">
            <tr>
              <td class="label"><a class="fn-backref" href="#id6" name="suffix">[4]</a></td>
              <td>Macros with <tt class="docutils literal"><span class="pre">_1ST</span></tt>,
                <tt class="docutils literal"><span class="pre">_2ND</span></tt>,
                or <tt class="docutils literal"><span class="pre">_3RD</span></tt>
                suffixes, if they appear, should be ignored for a different
                reason: They are deprecated and will be removed from the library
                soon.</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="section" id="preprocessor-library-abstractions">
        <h1><a name="preprocessor-library-abstractions">A.4   Preprocessor
            Library Abstractions</a></h1>
        <p>In this section we'll discuss the basic abstractions of the
          Preprocessor library, and give some simple examples of each.</p>
        <div class="section" id="repetition">
          <h2><a name="repetition">A.4.1   Repetition</a></h2>
          <p>The repeated generation of <tt class="docutils literal"><span class="pre">class</span>
              <span class="pre">T0</span></tt>, <tt class="docutils literal"><span

                class="pre">class</span> <span class="pre">T1</span></tt>... <tt

              class="docutils literal"><span class="pre">class</span> <span class="pre">T</span></tt><em>n</em>
            that we achieved using <tt class="docutils literal"><span class="pre">BOOST_PP_ENUM_PARAMS</span></tt>
            was a specific case of the general concept of <strong>horizontal
              repetition</strong>. The library also has a concept of vertical
            repetition, which we'll get to in a moment. Horizontal repetition
            macros are all found in the library's <tt class="docutils literal"><span

                class="pre">repetition/</span></tt> subdirectory.</p>
          <div class="section" id="horizontal-repetition">
            <h3><a name="horizontal-repetition">A.4.1.1   Horizontal Repetition</a></h3>
            <p>To generate the <tt class="docutils literal"><span class="pre">tiny_size</span></tt>
              specializations using horizontal repetition, we might write the
              following:</p>
            <pre class="literal-block">#include &lt;boost/preprocessor/repetition.hpp&gt;
#include &lt;boost/preprocessor/arithmetic/sub.hpp&gt;
#include &lt;boost/preprocessor/punctuation/comma_if.hpp&gt;

#define TINY_print(z, n, data) data

#define TINY_size(z, n, unused)                                 \
  template &lt;BOOST_PP_ENUM_PARAMS(n, class T)&gt;                   \
  struct tiny_size&lt;                                             \
      BOOST_PP_ENUM_PARAMS(n,T)                                 \
      BOOST_PP_COMMA_IF(n)                                      \
      BOOST_PP_ENUM(                                            \
          BOOST_PP_SUB(TINY_MAX_SIZE,n), TINY_print, none)      \
  &gt;                                                             \
    : mpl::int_&lt;n&gt; {};

BOOST_PP_REPEAT(TINY_MAX_SIZE, TINY_size, ~)

#undef TINY_size
#undef TINY_print
</pre>
            <!-- @import re
compile('all', pop = None)example.sub('BOOST_PP_REPEAT.*', '', flags = re.DOTALL) -->
            <p>The code generation process is kicked off by calling <tt class="docutils literal"><span

                  class="pre">BOOST_PP_REPEAT</span></tt>, a <strong>higher-order
                macro</strong> that repeatedly invokes the macro named by its
              second argument (<tt class="docutils literal"><span class="pre">TINY_size</span></tt>).
              The first argument specifies the number of repeated invocations,
              and the third one can be any data; it is passed on unchanged to
              the macro being invoked. In this case, <tt class="docutils literal"><span

                  class="pre">TINY_size</span></tt> doesn't use that data, so
              the choice to pass <tt class="docutils literal"><span class="pre">~</span></tt>
              was arbitrary.<a class="footnote-reference" href="#markers" id="id7"

                name="id7">[5]</a></p>
            <table class="docutils footnote" frame="void" id="markers" rules="none">
              <colgroup><col class="label" /><col /></colgroup>
              <tbody valign="top">
                <tr>
                  <td class="label"><a class="fn-backref" href="#id7" name="markers">[5]</a></td>
                  <td><tt class="docutils literal"><span class="pre">~</span></tt>
                    is not an <em>entirely</em> arbitrary choice. Both <tt class="docutils literal"><span

                        class="pre">@</span></tt> and <tt class="docutils literal"><span

                        class="pre">$</span></tt> might have been good choices,
                    except that they are technically not part of the basic
                    character set that C++ implementations are required to
                    support. An identifier like <tt class="docutils literal"><span

                        class="pre">ignored</span></tt> might be subject to
                    macro expansion, leading to unexpected results.</td>
                </tr>
              </tbody>
            </table>
            <p>Each time the <tt class="docutils literal"><span class="pre">TINY_size</span></tt>
              macro is invoked by <tt class="docutils literal"><span class="pre">BOOST_PP_REPEAT</span></tt>,
              it generates a different specialization of <tt class="docutils literal"><span

                  class="pre">tiny_size</span></tt>. The macro accepts three
              parameters.</p>
            <ul class="simple">
              <li><tt class="docutils literal"><span class="pre">z</span></tt>
                is related to the <tt class="docutils literal"><span class="pre">_Z</span></tt>
                macro suffix we mentioned earlier. You'll never need to use it
                except for optimization purposes, and can safely ignore it for
                now.</li>
              <li><tt class="docutils literal"><span class="pre">n</span></tt>
                is the repetition index. In repeated invocations of <tt class="docutils literal"><span

                    class="pre">TINY_size</span></tt>, <tt class="docutils literal"><span

                    class="pre">n</span></tt> will be <tt class="docutils literal"><span

                    class="pre">0</span></tt>, then <tt class="docutils literal"><span

                    class="pre">1</span></tt>, then <tt class="docutils literal"><span

                    class="pre">2</span></tt>, and so on.</li>
              <li><tt class="docutils literal"><span class="pre">unused</span></tt>,
                in this case, will be <tt class="docutils literal"><span class="pre">~</span></tt>
                on each repetition. In general, the final argument to a macro
                invoked by <tt class="docutils literal"><span class="pre">BOOST_PP_REPEAT</span></tt>
                is always the same as its invoker's final argument.</li>
            </ul>
            <p>Because its <em>replacement-list</em> covers several lines, all
              but the last line of <tt class="docutils literal"><span class="pre">TINY_size</span></tt>
              is continued with a trailing backslash. The first few of those
              lines just invoke <tt class="docutils literal"><span class="pre">BOOST_PP_ENUM_PARAMS</span></tt>
              (which we already used in the primary template) to generate
              comma-separated lists, so each invocation of <tt class="docutils literal"><span

                  class="pre">TINY_size</span></tt> produces something
              equivalent to:<a class="footnote-reference" href="#cont" id="id8"

                name="id8">[6]</a></p>
            <pre class="literal-block">template &lt;<strong>class T0, class T1, ... class T</strong><em>n-1</em>&gt;
struct tiny_size&lt;
    <strong>T0, T1, ... T</strong><em>n-1</em>
    <em>...more...</em> 
&gt; 
  : mpl::int_&lt;n&gt; {};
</pre>
            <table class="docutils footnote" frame="void" id="cont" rules="none">
              <colgroup><col class="label" /><col /></colgroup>
              <tbody valign="top">
                <tr>
                  <td class="label"><a class="fn-backref" href="#id8" name="cont">[6]</a></td>
                  <td>Note that the line continuation characters <em>and</em>
                    the newlines following them are removed by the preprocessor,
                    so the resulting code actually appears on a single line in
                    the preprocessed output.</td>
                </tr>
              </tbody>
            </table>
            <!-- @ignore() -->
            <p><tt class="docutils literal"><span class="pre">BOOST_PP_COMMA_IF</span></tt>
              generates a comma if its numeric argument is not <tt class="docutils literal"><span

                  class="pre">0</span></tt>. When <tt class="docutils literal"><span

                  class="pre">n</span></tt> is <tt class="docutils literal"><span

                  class="pre">0</span></tt>, the list generated by the preceding
              line will be empty, and a leading comma directly following the <tt

                class="docutils literal"><span class="pre">&lt;</span></tt>
              character would be ill-formed.</p>
            <p>The next line uses <tt class="docutils literal"><span class="pre">BOOST_PP_ENUM</span></tt>
              to generate <tt class="docutils literal"><span class="pre">TINY_MAX_SIZE-n</span></tt>
              comma-separated copies of <tt class="docutils literal"><span class="pre">none</span></tt>.
              <tt class="docutils literal"><span class="pre">BOOST_PP_ENUM</span></tt>
              is just like <tt class="docutils literal"><span class="pre">BOOST_PP_REPEAT</span></tt>
              except that it generates commas between repetitions, so its second
              argument (<tt class="docutils literal"><span class="pre">TINY_print</span></tt>,
              here) must have the same signature as <tt class="docutils literal"><span

                  class="pre">TINY_size</span></tt>. In this case, <tt class="docutils literal"><span

                  class="pre">TINY_print</span></tt> ignores its repetition
              index <tt class="docutils literal"><span class="pre">n</span></tt>,
              and simply yields its third argument, <tt class="docutils literal"><span

                  class="pre">none</span></tt>.</p>
            <p><tt class="docutils literal"><span class="pre">BOOST_PP_SUB</span></tt>
              implements token subtraction. It's crucial to understand that
              although the preprocessor <em>itself</em> can evaluate ordinary
              arithmetic expressions:</p>
            <pre class="literal-block">#define X 3
...
#if <strong>X - 1 &gt; 0</strong>  // OK
  <em>whatever</em>
#endif
</pre>
            <!-- @compile() -->
            <!-- @litre_translator.line_offset -= 7 -->
            <p>preprocessor <em>metaprograms</em> can only operate on tokens.
              Normally, when a macro in the Preprocessor library expects a
              numeric argument, it must be passed as a single token. If we had
              written <tt class="docutils literal"><span class="pre">TINY_MAX_SIZE-n</span></tt>
              instead of <tt class="docutils literal"><span class="pre">BOOST_PP_SUB(TINY_MAX_SIZE,n)</span></tt>
              above, the first argument to <tt class="docutils literal"><span class="pre">BOOST_PP_ENUM</span></tt>
              would have contained three tokens at each invocation: first <tt class="docutils literal"><span

                  class="pre">3-0</span></tt>, then <tt class="docutils literal"><span

                  class="pre">3-1</span></tt>, and finally <tt class="docutils literal"><span

                  class="pre">3-2</span></tt>. <tt class="docutils literal"><span

                  class="pre">BOOST_PP_SUB</span></tt>, though, generates
              single-token results: first <tt class="docutils literal"><span class="pre">3</span></tt>,
              then <tt class="docutils literal"><span class="pre">2</span></tt>,
              and finally <tt class="docutils literal"><span class="pre">1</span></tt>,
              in successive repetitions.</p>
            <div class="sidebar">
              <p class="first sidebar-title">Naming Conventions</p>
              <p class="last">Note that <tt class="docutils literal"><span class="pre">TINY_print</span></tt>
                and <tt class="docutils literal"><span class="pre">TINY_size</span></tt>
                are <tt class="docutils literal"><span class="pre">#undef</span></tt>'d
immediately
                after they're used, with no intervening <tt class="docutils literal"><span

                    class="pre">#include</span></tt>s. They can therefore be
                thought of as "local" macro definitions. Because the
                preprocessor doesn't respect scope boundaries, it's important to
                choose names carefully to prevent clashes. We recommend <tt class="docutils literal"><span

                    class="pre">PREFIXED_lower_case</span></tt> names for local
                macros and <tt class="docutils literal"><span class="pre">PREFIXED_UPPER_CASE</span></tt>
                names for global ones. The only exceptions are one-letter
                lowercase names, which are safe to use for local macros: No
                other header is likely to <tt class="docutils literal"><span class="pre">#define</span></tt>
                a global single-letter lowercase macro—that would be <em>very</em>
                bad manners.</p>
            </div>
          </div>
          <div class="section" id="vertical-repetition">
            <h3><a name="vertical-repetition">A.4.1.2   Vertical Repetition</a></h3>
            <p>If you send the previous example through your preprocessor,
              you'll see one long line containing something like this:</p>
            <pre class="literal-block">template &lt;&gt; struct tiny_size&lt; none , none , none &gt; : mpl::int_&lt;0&gt;
 {}; template &lt; class T0&gt; struct tiny_size&lt; T0 , none , none &gt; :
mpl::int_&lt;1&gt; {}; template &lt; class T0 , class T1&gt; struct tiny_size
&lt; T0 , T1 , none &gt; : mpl::int_&lt;2&gt; {};
</pre>
            <!-- @compile('all', pop = 1) -->
            <p>The distinguishing feature of horizontal repetition is that all
              instances of the repeated pattern are generated on the same line
              of preprocessed output. For some jobs, like generating the primary
              <tt class="docutils literal"><span class="pre">tiny_size</span></tt>
              template, that's perfectly appropriate. In this case, however,
              there are at least two disadvantages.</p>
            <ol class="arabic simple">
              <li>It's hard to verify that our metaprogram is doing the right
                thing without reformatting the resulting code by hand.</li>
              <li>The efficiency of nested horizontal repetitions varies widely
                across preprocessors. Each specialization generated by means of
                horizontal repetition contains three other horizontal
                repetitions: two invocations of <tt class="docutils literal"><span

                    class="pre">BOOST_PP_ENUM_PARAMS</span></tt> and one
                invocation of <tt class="docutils literal"><span class="pre">BOOST_PP_ENUM</span></tt>.
                When <tt class="docutils literal"><span class="pre">TINY_MAX_SIZE</span></tt>
                is <tt class="docutils literal"><span class="pre">3</span></tt>,
                you'll probably never care, but on at least one preprocessor
                still in use today, compilation begins to slow noticeably when <tt

                  class="docutils literal"><span class="pre">TINY_MAX_SIZE</span></tt>
                reaches <tt class="docutils literal"><span class="pre">8</span></tt>.<a

                  class="footnote-reference" href="#nest" id="id9" name="id9">[7]</a></li>
            </ol>
            <blockquote>
              <table class="docutils footnote" frame="void" id="nest" rules="none">
                <colgroup><col class="label" /><col /></colgroup>
                <tbody valign="top">
                  <tr>
                    <td class="label"><a class="fn-backref" href="#id9" name="nest">[7]</a></td>
                    <td>That said, other preprocessors can handle 256 * 256
                      nested repetitions without any speed problems whatsoever.</td>
                  </tr>
                </tbody>
              </table>
            </blockquote>
            <p>The solution to these problems, naturally, is <strong>vertical
                repetition</strong>, which generates instances of a pattern
              across multiple lines. The Preprocessor library provides two means
              of vertical repetition: <strong>local iteration</strong> and <strong>file
                iteration</strong>.</p>
            <div class="section" id="local-iteration">
              <h4><a name="local-iteration">Local Iteration</a></h4>
              <p>The most expedient way to demonstrate local iteration in our
                example is to replace the invocation of <tt class="docutils literal"><span

                    class="pre">BOOST_PP_REPEAT</span></tt> with the following:</p>
              <pre class="literal-block">#include &lt;boost/preprocessor/<strong>iteration/local.hpp</strong>&gt;

#define BOOST_PP_LOCAL_MACRO(n)   TINY_size(~, n, ~)
#define BOOST_PP_LOCAL_LIMITS     (0, <strong>TINY_MAX_SIZE - 1</strong>)
<strong>#include</strong> BOOST_PP_LOCAL_ITERATE()
</pre>
              <!-- @compile('all', pop = 1) -->
              <p>Local iteration repeatedly invokes the user-defined macro with
                the special name <tt class="docutils literal"><span class="pre">BOOST_PP_LOCAL_MACRO</span></tt>,
                whose argument will be an iteration index. Since we already had
                <tt class="docutils literal"><span class="pre">TINY_size</span></tt>
                lying around, we've just defined <tt class="docutils literal"><span

                    class="pre">BOOST_PP_LOCAL_MACRO</span></tt> to invoke it.
                The range of iteration indices are given by another user-defined
                macro, <tt class="docutils literal"><span class="pre">BOOST_PP_LOCAL_LIMITS</span></tt>,
                which must expand to a parenthesized pair of integer values
                representing the <em>inclusive</em> range of index values
                passed to <tt class="docutils literal"><span class="pre">BOOST_PP_LOCAL_MACRO</span></tt>.
                Note that this is one of the rare places where the library
                expects a numeric argument that can be an expression consisting
                of multiple tokens.</p>
              <p>Finally, the repetition is initiated by <tt class="docutils literal"><span

                    class="pre">#include</span></tt>-ing the result of invoking
                <tt class="docutils literal"><span class="pre">BOOST_PP_LOCAL_ITERATE</span></tt>,
                which will ultimately be a file in the Preprocessor library
                itself. You may find it surprising that many preprocessors can
                handle repeated file inclusion more quickly than nested
                horizontal repetition, but that is in fact the case.</p>
              <p>If we throw the new example at our preprocessor, we'll see the
                following, on three separate lines in the output:</p>
              <pre class="literal-block">template &lt;&gt; struct tiny_size&lt; none , none , none &gt; : mpl::int_&lt;0&gt;
 {};

template &lt; class T0&gt; struct tiny_size&lt; T0 , none , none &gt; : mpl::
int_&lt;1&gt; {};

template &lt; class T0 , class T1&gt; struct tiny_size&lt; T0 , T1 , none
&gt; : mpl::int_&lt;2&gt; {};
</pre>
              <!-- @compile('all', pop = 1) -->
              <p>That represents a great improvement in verifiability, but it's
                still not ideal. As <tt class="docutils literal"><span class="pre">TINY_MAX_SIZE</span></tt>
                grows, it gets harder and harder to see that the pattern is
                generating what we'd like. If we could get some more line breaks
                into the output it would retain a more recognizable form.</p>
              <p>Both repetition methods we've used so far have another
                drawback, though it doesn't show up in this example. Consider
                what would happen if <tt class="docutils literal"><span class="pre">tiny_size</span></tt>
                had a member function that we wanted to debug. If you've ever
                tried to use a debugger to step through a function generated by
                a preprocessor macro, you know that it's a frustrating
                experience at best: The debugger shows you the line from which
                the macro was ultimately invoked, which usually looks nothing at
                all like the code that was generated. Worse, as far as the
                debugger is concerned, <em>every</em> statement in that
                generated function occupies that same line.</p>
            </div>
            <div class="section" id="file-iteration">
              <h4><a name="file-iteration">File Iteration</a></h4>
              <p>Clearly, debuggability depends on preserving the association
                between generated code and the lines in the source file that
                describe the code pattern. File iteration generates pattern
                instances by repeatedly <tt class="docutils literal"><span class="pre">#include</span></tt>-ing
                the same source file. The effect of file iteration on
                debuggability is similar to that of templates: Although separate
                instances appear to occupy the same source lines in the
                debugger, we do have the experience of stepping through the
                function's source code.</p>
              <p>To apply file iteration in our example, we can replace our
                earlier local iteration code and the definition of <tt class="docutils literal"><span

                    class="pre">TINY_size</span></tt>, with:</p>
              <pre class="literal-block">#include &lt;boost/preprocessor/iteration/iterate.hpp&gt;
#define BOOST_PP_ITERATION_LIMITS (0, TINY_MAX_SIZE - 1)
#define BOOST_PP_FILENAME_1       "tiny_size_spec.hpp"
#include BOOST_PP_ITERATE()
</pre>
              <p><tt class="docutils literal"><span class="pre">BOOST_PP_ITERATION_LIMITS</span></tt>
                follows the same pattern as <tt class="docutils literal"><span

                    class="pre">BOOST_PP_LOCAL_LIMITS</span></tt> did, allowing
                us to specify an inclusive range of iteration indices. <tt class="docutils literal"><span

                    class="pre">BOOST_PP_FILENAME_1</span></tt> specifies the
                name of the file to repeatedly <tt class="docutils literal"><span

                    class="pre">#include</span></tt> (we'll show you that file
                in a moment). The trailing <tt class="docutils literal"><span class="pre">1</span></tt>
                indicates that this is the first nesting level of file
                iteration—should we need to invoke file iteration again from
                within <tt class="docutils literal"><span class="pre">tiny_size_spec.hpp</span></tt>,
                we'd need to use <tt class="docutils literal"><span class="pre">BOOST_PP_FILENAME_2</span></tt>
                instead.</p>
              <p>The contents of <tt class="docutils literal"><span class="pre">tiny_size_spec.hpp</span></tt>
                should look familiar to you; most of it is the same as <tt class="docutils literal"><span

                    class="pre">TINY_size</span></tt>'s <em>replacement-list</em>,
                without the backslashes:</p>
              <pre class="literal-block">#define n BOOST_PP_ITERATION()

template &lt;BOOST_PP_ENUM_PARAMS(n, class T)&gt;
struct tiny_size&lt;
    BOOST_PP_ENUM_PARAMS(n,T)
    BOOST_PP_COMMA_IF(n)
    BOOST_PP_ENUM(BOOST_PP_SUB(TINY_MAX_SIZE,n), TINY_print, none)
&gt;
  : mpl::int_&lt;n&gt; {};

#undef n
</pre>
              <!-- @import tempfile, os
open(os.path.join(tempfile.gettempdir(),'tiny_size_spec.hpp'), 'w'   ).write(str(example))ignore()vertical_options = ['-I'+tempfile.gettempdir(), '-c']
compile('all', options = vertical_options, pop = 1) -->
              <p>The Library transmits the iteration index to us in the result
                of <tt class="docutils literal"><span class="pre">BOOST_PP_ITERATION()</span></tt>;
                <tt class="docutils literal"><span class="pre">n</span></tt> is
                nothing more than a convenient local macro used to reduce
                syntactic noise. Note that we didn't use <tt class="docutils literal"><span

                    class="pre">#include</span></tt> guards because we need <tt

                  class="docutils literal"><span class="pre">tiny_size_spec.hpp</span></tt>
                to be processed multiple times.</p>
              <p>The preprocessed result should now preserve the line structure
                of the pattern and be more verifiable for larger values of <tt

                  class="docutils literal"><span class="pre">TINY_MAX_SIZE</span></tt>.
                For instance, when <tt class="docutils literal"><span class="pre">TINY_MAX_SIZE</span></tt>
                is <tt class="docutils literal"><span class="pre">8</span></tt>,
                the following excerpt appears in the output of GCC's
                preprocessing phase:</p>
              <pre class="literal-block"><em>...</em>
template &lt; class T0 , class T1 , class T2 , class T3&gt;
struct tiny_size&lt;
    T0 , T1 , T2 , T3
    ,
    none , none , none , none
&gt;
  : mpl::int_&lt;4&gt; {};

template &lt; class T0 , class T1 , class T2 , class T3 , class T4&gt;
struct tiny_size&lt;
    T0 , T1 , T2 , T3 , T4
    ,
    none , none , none
&gt;
  : mpl::int_&lt;5&gt; {};
<em>...etc.</em>
</pre>
              <!-- @compile('all', options = vertical_options + ['-DTINY_MAX_SIZE=8']) -->
            </div>
            <div class="section" id="self-iteration">
              <h4><a name="self-iteration">Self-Iteration</a></h4>
              <p>Creating an entirely new file like <tt class="docutils literal"><span

                    class="pre">tiny_size_spec.hpp</span></tt> each time we want
                to express a trivial code pattern for file repetition can be
                inconvenient. Fortunately, the library provides a macro that
                allows us to place the pattern right in the file that invokes
                the iteration. <tt class="docutils literal"><span class="pre">BOOST_PP_IS_ITERATING</span></tt>
                is defined to a nonzero value whenever we're inside an
                iteration. We can use that value to select between the part of a
                file that invokes the iteration and the part that provides the
                repeated pattern. Here's a complete <tt class="docutils literal"><span

                    class="pre">tiny_size.hpp</span></tt> file that demonstrates
                self-iteration. Note in particular the placement and use of the
                <tt class="docutils literal"><span class="pre">#include</span></tt>
                guard <tt class="docutils literal"><span class="pre">TINY_SIZE_HPP_INCLUDED</span></tt>:</p>
              <pre class="literal-block">#ifndef <strong>BOOST_PP_IS_ITERATING</strong>

#  ifndef TINY_SIZE_HPP_INCLUDED
#    define TINY_SIZE_HPP_INCLUDED

#    include &lt;boost/preprocessor/repetition.hpp&gt;
#    include &lt;boost/preprocessor/arithmetic/sub.hpp&gt;
#    include &lt;boost/preprocessor/punctuation/comma_if.hpp&gt;
#    include &lt;boost/preprocessor/iteration/iterate.hpp&gt;

#    ifndef TINY_MAX_SIZE
#      define TINY_MAX_SIZE 3  // default maximum size is 3
#    endif

// primary template
template &lt;BOOST_PP_ENUM_PARAMS(TINY_MAX_SIZE, class T)&gt;
struct tiny_size
  : mpl::int_&lt;TINY_MAX_SIZE&gt;
{};

// generate specializations
#    define BOOST_PP_ITERATION_LIMITS (0, TINY_MAX_SIZE - 1)
#    define BOOST_PP_FILENAME_1       "tiny_size.hpp" // this file
#    include BOOST_PP_ITERATE()

#  endif // TINY_SIZE_HPP_INCLUDED

#else // <strong>BOOST_PP_IS_ITERATING</strong>

#  define n BOOST_PP_ITERATION()

#  define TINY_print(z, n, data) data

// specialization pattern
template &lt;BOOST_PP_ENUM_PARAMS(n, class T)&gt;
struct tiny_size&lt;
    BOOST_PP_ENUM_PARAMS(n,T)
    BOOST_PP_COMMA_IF(n)
    BOOST_PP_ENUM(BOOST_PP_SUB(TINY_MAX_SIZE,n), TINY_print, none)
&gt;
  : mpl::int_&lt;n&gt; {};

#  undef TINY_print
#  undef n

#endif // <strong>BOOST_PP_IS_ITERATING</strong>
</pre>
              <!-- @compile(source_file = 'tiny_size.hpp') --> </div>
            <div class="section" id="more">
              <h4><a name="more">More</a></h4>
              <p>There's a good deal more to file iteration than what we've been
                able to show you here. For more details, we encourage you to
                delve into the library's electronic documentation of <tt class="docutils literal"><span

                    class="pre">BOOST_PP_ITERATE</span></tt> and friends. Also,
                it's important to note that no single technique for repetition
                is superior to any other: Your choice may depend on convenience,
                verifiability, debuggability, compilation speed, and your own
                sense of "logical coherence."</p>
            </div>
          </div>
        </div>
        <div class="section" id="arithmetic-logical-and-comparison-operations">
          <h2><a name="arithmetic-logical-and-comparison-operations">A.4.2   Arithmetic,
              Logical, and Comparison Operations</a></h2>
          <p>As we mentioned earlier, many of the Preprocessor library
            interfaces require single-token numeric arguments, and when those
            numbers need to be computed arithmetically, straightforward
            arithmetic expressions are inappropriate. We used <tt class="docutils literal"><span

                class="pre">BOOST_PP_SUB</span></tt> to subtract two numeric
            tokens in our <tt class="docutils literal"><span class="pre">tiny_size</span></tt>
            examples. The library contains a suite of operations for
            non-negative integral token arithmetic in its <tt class="docutils literal"><span

                class="pre">arithmetic/</span></tt> subdirectory, as shown in
            Table A.1</p>
          <table border="1" class="docutils">
            <caption>Preprocessor Library Arithmetic Operations</caption> <colgroup>
              <col width="44%" /> <col width="56%" /> </colgroup>
            <thead valign="bottom">
              <tr>
                <th>Expression</th>
                <th>Value of Single Token Result</th>
              </tr>
            </thead>
            <tbody valign="top">
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_ADD(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">+</span> <span class="pre">y</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_DEC(x)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">-</span> <span class="pre">1</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_DIV(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">/</span> <span class="pre">y</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_INC(x)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">+</span> <span class="pre">1</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_MOD(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">%</span> <span class="pre">y</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_MUL(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">*</span> <span class="pre">y</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_SUB(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">-</span> <span class="pre">y</span></tt></td>
              </tr>
            </tbody>
          </table>
          <p>The <tt class="docutils literal"><span class="pre">logical/</span></tt>
            subdirectory contains the convenient Boolean token operations shown
            in Table A.2 and the more efficient operations shown in Table A.3,
            which require that their operands are either <tt class="docutils literal"><span

                class="pre">0</span></tt> or <tt class="docutils literal"><span

                class="pre">1</span></tt> (a single bit).</p>
          <table border="1" class="docutils">
            <caption>Preprocessor Library Integer Logical Operations</caption> <colgroup>
              <col width="44%" /> <col width="56%" /> </colgroup>
            <thead valign="bottom">
              <tr>
                <th>Expression</th>
                <th>Value of Single Token Result</th>
              </tr>
            </thead>
            <tbody valign="top">
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_AND(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">&amp;&amp;</span> <span class="pre">y</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_NOR(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">!(x</span> <span

                      class="pre">||</span> <span class="pre">y)</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_OR(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">||</span> <span class="pre">y</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_XOR(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">(bool)x</span>
                    <span class="pre">!=</span> <span class="pre">(bool)y</span>  
                    <span class="pre">?</span> <span class="pre">1</span> <span

                      class="pre">:</span> <span class="pre">0</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_NOT(x)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">?</span> <span class="pre">0</span> <span class="pre">:</span>
                    <span class="pre">1</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_BOOL(x)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">?</span> <span class="pre">1</span> <span class="pre">:</span>
                    <span class="pre">0</span></tt></td>
              </tr>
            </tbody>
          </table>
          <table border="1" class="docutils">
            <caption>Preprocessor Library Bit Logical Operations</caption> <colgroup>
              <col width="44%" /> <col width="56%" /> </colgroup>
            <thead valign="bottom">
              <tr>
                <th>Expression</th>
                <th>Value of Single Token Result</th>
              </tr>
            </thead>
            <tbody valign="top">
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_BITAND(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">&amp;&amp;</span> <span class="pre">y</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_BITNOR(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">!(x</span> <span

                      class="pre">||</span> <span class="pre">y)</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_BITOR(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">||</span> <span class="pre">y</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_BITXOR(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">(bool)x</span>
                    <span class="pre">!=</span> <span class="pre">(bool)y</span>  
                    <span class="pre">?</span> <span class="pre">1</span> <span

                      class="pre">:</span> <span class="pre">0</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_COMPL(x)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">?</span> <span class="pre">0</span> <span class="pre">:</span>
                    <span class="pre">1</span></tt></td>
              </tr>
            </tbody>
          </table>
          <p>Finally, the <tt class="docutils literal"><span class="pre">comparison/</span></tt>
            subdirectory provides the token integral comparison operations shown
            in Table A.4.</p>
          <table border="1" class="docutils">
            <caption>Preprocessor Library Comparison Operations</caption> <colgroup>
              <col width="46%" /> <col width="54%" /> </colgroup>
            <thead valign="bottom">
              <tr>
                <th>Expression</th>
                <th>Value of Single Token Result</th>
              </tr>
            </thead>
            <tbody valign="top">
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_EQUAL(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">==</span> <span class="pre">y</span>   <span

                      class="pre">?</span> <span class="pre">1</span> <span class="pre">:</span>
                    <span class="pre">0</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_NOT_EQUAL(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">!=</span> <span class="pre">y</span>   <span

                      class="pre">?</span> <span class="pre">1</span> <span class="pre">:</span>
                    <span class="pre">0</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_LESS(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">&lt;</span> <span class="pre">y</span>    <span

                      class="pre">?</span> <span class="pre">1</span> <span class="pre">:</span>
                    <span class="pre">0</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_LESS_EQUAL(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">&lt;=</span> <span class="pre">y</span>   <span

                      class="pre">?</span> <span class="pre">1</span> <span class="pre">:</span>
                    <span class="pre">0</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_GREATER(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">&gt;</span> <span class="pre">y</span>    <span

                      class="pre">?</span> <span class="pre">1</span> <span class="pre">:</span>
                    <span class="pre">0</span></tt></td>
              </tr>
              <tr>
                <td><tt class="docutils literal"><span class="pre">BOOST_PP_GREATER_EQUAL(x,y)</span></tt></td>
                <td><tt class="docutils literal"><span class="pre">x</span> <span

                      class="pre">&gt;=</span> <span class="pre">y</span>   <span

                      class="pre">?</span> <span class="pre">1</span> <span class="pre">:</span>
                    <span class="pre">0</span></tt></td>
              </tr>
            </tbody>
          </table>
          <p>Because it's common to have a choice among several workable
            comparison operators, it may be useful to know that <tt class="docutils literal"><span

                class="pre">BOOST_PP_EQUAL</span></tt> and <tt class="docutils literal"><span

                class="pre">BOOST_PP_NOT_EQUAL</span></tt> are likely to be O(1)
            while the other comparison operators are generally slower.</p>
        </div>
        <div class="section" id="control-structures">
          <h2><a name="control-structures">A.4.3   Control Structures</a></h2>
          <p>In its <tt class="docutils literal"><span class="pre">control/</span></tt>
            directory, the Preprocessor Library supplies a macro <tt class="docutils literal"><span

                class="pre">BOOST_PP_IF(c,t,f)</span></tt> that fulfills a
            similar role to the one filled by <tt class="docutils literal"><span

                class="pre">mpl::if_</span></tt>. To explore the "control"
            group, we'll generate code for a framework of generic function
            objects: the Boost Function Library.<a class="footnote-reference" href="#function"

              id="id10" name="id10">[8]</a> <tt class="docutils literal"><span

                class="pre">boost::function</span></tt> is partially specialized
            to match function type arguments of each arity up to the maximum
            supported by the library:</p>
          <pre class="literal-block">template &lt;class Signature&gt; struct function;   // primary template

template &lt;class R&gt;                                   // arity = 0
struct function&lt;R()&gt;
  <em>definition not shown...</em>

template &lt;class R, class A0&gt;                         // arity = 1
struct function&lt;R(A0)&gt;
  <em>definition not shown...</em>

template &lt;class R, class A0, class A1&gt;               // arity = 2
struct function&lt;R(A0,A1)&gt;
  <em>definition not shown...</em>

template &lt;class R, class A0, class A1, class A2&gt;     // arity = 3
struct function&lt;R(A0,A1,A2)&gt;
  <em>definition not shown...</em>

<em>etc.</em>
</pre>
          <!-- @example.replace(')>', ')>;')
compile() -->
          <table class="docutils footnote" frame="void" id="function" rules="none">
            <colgroup><col class="label" /><col /></colgroup>
            <tbody valign="top">
              <tr>
                <td class="label"><a class="fn-backref" href="#id10" name="function">[8]</a></td>
                <td>We touched briefly on the design of Boost Function when we
                  discussed type erasure in Chapter 9. See the Function library
                  documentation at <tt class="docutils literal"><span class="pre">boost_1_32_0/libs/function/index.html</span></tt>
                  on the CD that accompanies this book for more information.</td>
              </tr>
            </tbody>
          </table>
          <p>We've already covered a few strategies that can be used to generate
            the pattern above, so we won't belabor that part of the problem; the
            file iteration approach we used for <tt class="docutils literal"><span

                class="pre">tiny_size</span></tt> would be fine:</p>
          <pre class="literal-block">#ifndef BOOST_PP_IS_ITERATING

#  ifndef BOOST_FUNCTION_HPP_INCLUDED
#    define BOOST_FUNCTION_HPP_INCLUDED

#    include &lt;boost/preprocessor/repetition.hpp&gt;
#    include &lt;boost/preprocessor/iteration/iterate.hpp&gt;

#    ifndef FUNCTION_MAX_ARITY
#      define FUNCTION_MAX_ARITY 15
#    endif

<strong>template &lt;class Signature&gt; struct function;</strong>   // primary template

// generate specializations
#    define BOOST_PP_ITERATION_LIMITS (0, FUNCTION_MAX_ARITY)
#    define BOOST_PP_FILENAME_1    "boost/function.hpp" // this file
#    include BOOST_PP_ITERATE()

#  endif // BOOST_FUNCTION_HPP_INCLUDED

#else // BOOST_PP_IS_ITERATING

#  define n BOOST_PP_ITERATION()

// specialization pattern
<strong>template &lt;class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class A)&gt;</strong>
<strong>struct function&lt;R ( BOOST_PP_ENUM_PARAMS(n,A) )&gt;</strong>
  <em>definition not shown...</em>

#  undef n

#endif // BOOST_PP_IS_ITERATING
</pre>
          <p><tt class="docutils literal"><span class="pre">BOOST_PP_ENUM_TRAILING_PARAMS</span></tt>,
            used above, is just like <tt class="docutils literal"><span class="pre">BOOST_PP_ENUM_PARAMS</span></tt>
            except that when its first argument is not <tt class="docutils literal"><span

                class="pre">0</span></tt>, it generates a leading comma.</p>
          <!-- @example.replace_emphasis(';//')
tmpdir = tempfile.gettempdir()tmpboost = os.path.join(tmpdir,'boost')try: os.mkdir(tmpboost)except: pass
tmp_boost_function = os.path.join(tmpdir, 'boost/function.hpp')compile(    options = vertical_options  , source_file = tmp_boost_function
  , pop = None) -->
          <div class="section" id="argument-selection">
            <h3><a name="argument-selection">A.4.3.1   Argument Selection</a></h3>
            <p>For the sake of interoperability with C++ standard library
              algorithms, it might be nice if <tt class="docutils literal"><span

                  class="pre">function</span></tt>s of one or two arguments were
              derived from appropriate specializations of <tt class="docutils literal"><span

                  class="pre">std::unary_function</span></tt> or <tt class="docutils literal"><span

                  class="pre">std::binary_function</span></tt>, respectively.<a

                class="footnote-reference" href="#ebo" id="id11" name="id11">[9]</a>
              <tt class="docutils literal"><span class="pre">BOOST_PP_IF</span></tt>
              is a great tool for dealing with special cases:</p>
            <pre class="literal-block">#  include &lt;boost/preprocessor/control/if.hpp&gt;
#  include &lt;boost/preprocessor/comparison/equal.hpp&gt;

// specialization pattern
template &lt;class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class A)&gt;
struct function&lt;R ( BOOST_PP_ENUM_PARAMS(n,A) )&gt;
  BOOST_PP_IF(
      BOOST_PP_EQUAL(n,2), <strong>: std::binary_function&lt;A0, A1, R&gt;</strong>
    , BOOST_PP_IF(
          BOOST_PP_EQUAL(n,1), <strong>: std::unary_function&lt;A0, R&gt;</strong>
        , <em>...empty argument...</em>
      )
  )
{ <em>...class body omitted...</em> };
</pre>
            <!-- @pp_failure() -->
            <table class="docutils footnote" frame="void" id="ebo" rules="none">
              <colgroup><col class="label" /><col /></colgroup>
              <tbody valign="top">
                <tr>
                  <td class="label"><a class="fn-backref" href="#id11" name="ebo">[9]</a></td>
                  <td>While derivation from <tt class="docutils literal"><span

                        class="pre">std::unary_function</span></tt> or <tt class="docutils literal"><span

                        class="pre">std::binary_function</span></tt> might be
                    necessary for interoperability with some older library
                    implementations, it may inhibit the Empty Base Optimization
                    (EBO) from taking effect when two such derived classes are
                    part of the same object. For more information, see section
                    9.4. In general, it's better to expose <tt class="docutils literal"><span

                        class="pre">first_argument_type</span></tt>, <tt class="docutils literal"><span

                        class="pre">second_argument_type</span></tt>, and <tt class="docutils literal"><span

                        class="pre">result_type</span></tt> <tt class="docutils literal"><span

                        class="pre">typedef</span></tt>s directly.</td>
                </tr>
              </tbody>
            </table>
            <p>Well, our first attempt has run into several problems. First off,
              you're not allowed to pass an empty argument to the preprocessor.<a

                class="footnote-reference" href="#c99" id="id12" name="id12">[3]</a>
              Secondly, because angle brackets don't get special treatment, the
              commas in the <tt class="docutils literal"><span class="pre">std::unary_function</span></tt>
              and <tt class="docutils literal"><span class="pre">std::binary_function</span></tt>
              specializations above are treated as macro argument separators,
              and the preprocessor will complain that we've passed the wrong
              number of arguments to <tt class="docutils literal"><span class="pre">BOOST_PP_IF</span></tt>
              in two places.</p>
            <p>Because it captures all of the issues, let's focus on the inner <tt

                class="docutils literal"><span class="pre">BOOST_PP_IF</span></tt>
              invocation for a moment. The strategy that <tt class="docutils literal"><span

                  class="pre">mpl::eval_if</span></tt> uses, of selecting a
              nullary function to invoke, could work nicely here. The
              preprocessor doesn't have a direct analogue for <tt class="docutils literal"><span

                  class="pre">mpl::eval_if</span></tt>, but it doesn't really
              need one: We can get the right effect by adding a second set of
              parentheses to <tt class="docutils literal"><span class="pre">BOOST_PP_IF</span></tt>.</p>
            <pre class="literal-block">#define BOOST_FUNCTION_unary()    : std::unary_function&lt;A0,R&gt;
#define BOOST_FUNCTION_empty()    // nothing

...

    , BOOST_PP_IF(
          BOOST_PP_EQUAL(n,1), BOOST_FUNCTION_unary
        , BOOST_FUNCTION_empty
      )<strong>()</strong>

#undef BOOST_FUNCTION_empty
#undef BOOST_FUNCTION_unary
</pre>
            <!-- @ignore() -->
            <p>A nullary macro that generates nothing is so commonly needed that
              the library's "facilities" group provides one: <tt class="docutils literal"><span

                  class="pre">BOOST_PP_EMPTY</span></tt>. To complete the
              example we'll need to delay evaluation all the way to the outer <tt

                class="docutils literal"><span class="pre">BOOST_PP_IF</span></tt>
              invocation, because <tt class="docutils literal"><span class="pre">std::binary_function&lt;A0,A1,R&gt;</span></tt>
              also has a "comma problem":</p>
            <pre class="literal-block">#  include &lt;boost/preprocessor/<strong>facilities/empty.hpp</strong>&gt;

#  define BOOST_FUNCTION_binary() : std::binary_function&lt;A0,A1,R&gt;
#  define BOOST_FUNCTION_unary()  : std::unary_function&lt;A0,R&gt;

// specialization pattern
template &lt;class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class A)&gt;
struct function&lt;R ( BOOST_PP_ENUM_PARAMS(n,A) )&gt;
  BOOST_PP_IF(
      BOOST_PP_EQUAL(n,2), BOOST_FUNCTION_binary
    , BOOST_PP_IF(
          BOOST_PP_EQUAL(n,1), BOOST_FUNCTION_unary
        , <strong>BOOST_PP_EMPTY</strong>
      )
  )<strong>()</strong>
{ 
    <em>...class body omitted...</em>
};

#  undef BOOST_FUNCTION_unary
#  undef BOOST_FUNCTION_binary
#  undef n
</pre>
            <!-- @stack.pop()
stack[-1].replace('// specialization pattern', '////\n%s\n////' % str(example))compile(source_file = tmp_boost_function, pop = None) -->
            <p>Note that because we happened to be using file iteration, we
              could have also used <tt class="docutils literal"><span class="pre">#if</span></tt>
              on <tt class="docutils literal"><span class="pre">n</span></tt>'s
              value directly:</p>
            <pre class="literal-block">  template &lt;class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class A)&gt;
  struct function&lt;R ( BOOST_PP_ENUM_PARAMS(n,A) )&gt;
<strong>#if n == 2</strong>
    : std::binary_function&lt;A0, A1, R&gt;
<strong>#elif n == 1</strong>
    : std::unary_function&lt;A0, R&gt;
<strong>#endif</strong>
</pre>
            <!-- @stack.pop()
stack[-1].sub(    r'////.*////', '////\n%s\n////' % str(example), flags = re.DOTALL)compile(source_file = tmp_boost_function, pop = None) -->
            <p><tt class="docutils literal"><span class="pre">BOOST_PP_IF</span></tt>
              has the advantage of enabling us to encapsulate the logic in a
              reusable macro, parameterized on <tt class="docutils literal"><span

                  class="pre">n</span></tt>, that is compatible with all
              repetition constructs:</p>
            <pre class="literal-block">#define BOOST_FUNCTION_BASE(n)                                \
    BOOST_PP_IF(BOOST_PP_EQUAL(n,2), BOOST_FUNCTION_binary    \
      , BOOST_PP_IF(BOOST_PP_EQUAL(n,1), BOOST_FUNCTION_unary \
           , BOOST_PP_EMPTY                                   \
        )                                                     \
    )()
</pre>
            <!-- @compile(options = ['-E']) --> </div>
          <div class="section" id="other-selection-constructs">
            <h3><a name="other-selection-constructs">A.4.3.2   Other Selection
                Constructs</a></h3>
            <p><tt class="docutils literal"><span class="pre">BOOST_PP_IDENTITY</span></tt>,
              also in the "facilities" group, is an interesting cousin of <tt class="docutils literal"><span

                  class="pre">BOOST_PP_EMPTY</span></tt>:</p>
            <pre class="literal-block">#define BOOST_PP_IDENTITY(tokens) tokens BOOST_PP_EMPTY
</pre>
            <!-- @ignore() -->
            <p>You can think of it as creating a nullary macro that returns <tt

                class="docutils literal"><span class="pre">tokens</span></tt>:
              When empty parentheses are appended, the trailing <tt class="docutils literal"><span

                  class="pre">BOOST_PP_EMPTY</span></tt> is expanded leaving
              just <tt class="docutils literal"><span class="pre">tokens</span></tt>
              behind. If we had wanted inheritance from <tt class="docutils literal"><span

                  class="pre">mpl::empty_base</span></tt> when <tt class="docutils literal"><span

                  class="pre">function</span></tt>'s arity is not one or two, we
              could have used <tt class="docutils literal"><span class="pre">BOOST_PP_IDENTITY</span></tt>:</p>
            <pre class="literal-block">// specialization pattern
template &lt;class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class A)&gt;
struct function&lt;R ( BOOST_PP_ENUM_PARAMS(n,A) )&gt;
  BOOST_PP_IF(
      BOOST_PP_EQUAL(n,2), BOOST_FUNCTION_binary
    , BOOST_PP_IF(
          BOOST_PP_EQUAL(n,1), BOOST_FUNCTION_unary
        , <strong>BOOST_PP_IDENTITY(: mpl::empty_base)</strong>
      )
  )<strong>()</strong>
{ 
    <em>...class body omitted...</em>
};
</pre>
            <!-- @stack.pop()
stack[-1].sub(    r'////.*////', '////\n%s\n////' % str(example), flags = re.DOTALL)compile(source_file = tmp_boost_function, pop = None) -->
            <p>It's also worth knowing about <tt class="docutils literal"><span

                  class="pre">BOOST_PP_EXPR_IF</span></tt>, which generates its
              second argument or nothing, depending on the Boolean value of its
              first:</p>
            <pre class="literal-block">#define BOOST_PP_EXPR_IF(c,tokens)                           \
   BOOST_PP_IF(c,BOOST_PP_IDENTITY(tokens),BOOST_PP_EMPTY)()
</pre>
            <!-- @example.append(
  'int BOOST_PP_EXPR_IF(1,main) BOOST_PP_EXPR_IF(0,quack) () {}')compile() -->
            <p>So <tt class="docutils literal"><span class="pre">BOOST_PP_EXPR_IF(1,foo)</span></tt>
              expands to <tt class="docutils literal"><span class="pre">foo</span></tt>,
              while <tt class="docutils literal"><span class="pre">BOOST_PP_EXPR_IF(0,foo)</span></tt>
              expands to nothing.</p>
          </div>
        </div>
        <div class="section" id="token-pasting">
          <h2><a name="token-pasting">A.4.4   Token Pasting</a></h2>
          <p>It would be nice if there were a generic way to access the return
            and parameter types of <em>all</em> function objects, rather than
            just the unary and binary ones. A metafunction returning the
            signature as an MPL sequence would do the trick. We could just
            specialize <tt class="docutils literal"><span class="pre">signature</span></tt>
            for each <tt class="docutils literal"><span class="pre">function</span></tt>
            arity:</p>
          <pre class="literal-block">template &lt;class F&gt; struct signature; // primary template

// partial specializations for boost::function
template &lt;class R&gt;
struct signature&lt;function&lt;R()&gt; &gt; 
  : mpl::vector1&lt;R&gt; {};

template &lt;class R, class A0&gt;
struct signature&lt;function&lt;R(A0)&gt; &gt; 
  : mpl::vector2&lt;R,A0&gt; {};

template &lt;class R, class A0, class A1&gt;
struct signature&lt;function&lt;R(A0,A1)&gt; &gt; 
  : mpl::vector3&lt;R,A0,A1&gt; {};

...
</pre>
          <!-- @example.prepend('template <class T> struct function;')
compile() -->
          <p>To generate these specializations, we might add the following to
            our pattern:</p>
          <pre class="literal-block">template &lt;class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class A)&gt;
struct signature&lt;function&lt;R( BOOST_PP_ENUM_PARAMS(n,A) )&gt; &gt;
  : mpl::<strong>BOOST_PP_CAT</strong>(vector,n)&lt;
      R BOOST_PP_ENUM_TRAILING_PARAMS(n,A)
    &gt; {};
</pre>
          <!-- @stack.pop()
stack[-1].replace(    ';//', ''';//    template <class T> struct signature;    %s''' % example)
compile(source_file = tmp_boost_function) -->
          <p><tt class="docutils literal"><span class="pre">BOOST_PP_CAT</span></tt>
            implements <strong>token pasting</strong>; its two arguments are
            "glued" together into a single token. Since this is a
            general-purpose macro, it sits in <tt class="docutils literal"><span

                class="pre">cat.hpp</span></tt> at the top level of the
            library's directory tree.</p>
          <p>Although the preprocessor has a built-in token-pasting operator, <tt

              class="docutils literal"><span class="pre">##</span></tt>, it only
            works within a macro definition. If we'd used it here, it wouldn't
            have taken effect at all:</p>
          <pre class="literal-block">template &lt;class R&gt;
struct signature&lt;function&lt;R()&gt; &gt; 
  : mpl::<strong>vector##1</strong>&lt;R&gt; {};

template &lt;class R, class A0&gt;
struct signature&lt;function&lt;R(A0)&gt; &gt; 
  : mpl::<strong>vector##2</strong>&lt;R,A0&gt; {};

template &lt;class R, class A0, class A1&gt;
struct signature&lt;function&lt;R(A0,A1)&gt; &gt; 
  : mpl::<strong>vector##3</strong>&lt;R,A0,A1&gt; {};

...
</pre>
          <!-- @example.replace('##','')
example.prepend('''    template <class T> struct function;    template <class T> struct signature;''')
compile() -->
          <p>Also, <tt class="docutils literal"><span class="pre">##</span></tt>
            often yields surprising results by taking effect before its
            arguments have been expanded:</p>
          <pre class="literal-block">#define N           10
#define VEC(i)      vector##i

VEC(N)           // vectorN
</pre>
          <!-- @example.wrap('typedef int vectorN;', 'x;')
compile() -->
          <p>By contrast, <tt class="docutils literal"><span class="pre">BOOST_PP_CAT</span></tt>
            delays concatenation until after its arguments have been fully
            evaluated:</p>
          <pre class="literal-block">#define N           10
#define VEC(i)      BOOST_PP_CAT(vector,i)

VEC(N)           // vector10
</pre>
          <!-- @example.wrap('''
  #include <boost/preprocessor/cat.hpp>  typedef int vector10;  ''', 'x;')compile() -->
        </div>
        <div class="section" id="data-types">
          <h2><a name="data-types">A.4.5   Data Types</a></h2>
          <p>The Preprocessor library also provides <strong>data types</strong>,
            which you can think of as being analogous to the MPL's type
            sequences. Preprocessor data types store <em>macro arguments</em>
            instead of C++ types.</p>
          <div class="section" id="sequences">
            <h3><a name="sequences">A.4.5.1   Sequences</a></h3>
            <p>A <strong>sequence</strong> (or <strong>seq</strong> for short)
              is any string of nonempty parenthesized <em>macro arguments</em>.
              For instance, here's a three-element sequence:</p>
            <pre class="literal-block">#define MY_SEQ   (f(12))(a + 1)(foo)
</pre>
            <!-- @ignore() -->
            <p>Here's how we might use a sequence to generate specializations of
              the <tt class="docutils literal"><span class="pre">is_integral</span></tt>
              template from the Boost Type Traits library (see Chapter 2):</p>
            <pre class="literal-block">#include &lt;boost/preprocessor/seq.hpp&gt;

template &lt;class T&gt;
struct is_integral : mpl::false_ {}; 

// a seq of integral types with unsigned counterparts
#define BOOST_TT_basic_ints            (char)(short)(int)(long)

// generate a seq containing "signed t" and "unsigned t"
#define BOOST_TT_int_pair(r,data,t)      (signed t)(unsigned t)

// a seq of all the integral types
#define BOOST_TT_ints                                           \
    (bool)(char)                                                \
    BOOST_PP_SEQ_FOR_EACH(BOOST_TT_int_pair, ~, BOOST_TT_basic_ints)

// generate an is_integral specialization for type t
#define BOOST_TT_is_integral_spec(r,data,t) \
   template &lt;&gt;                              \
   struct is_integral&lt;t&gt; : mpl::true_ {}; 

BOOST_PP_SEQ_FOR_EACH(BOOST_TT_is_integral_spec, ~, BOOST_TT_ints)

#undef BOOST_TT_is_integral_spec
#undef BOOST_TT_ints
#undef BOOST_TT_int_pair
#undef BOOST_TT_basic_ints
</pre>
            <!-- @compile() -->
            <p><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_FOR_EACH</span></tt>
              is a higher-order macro, similar to <tt class="docutils literal"><span

                  class="pre">BOOST_PP_REPEAT</span></tt>, that invokes its
              first argument on each element of its third argument.</p>
            <p>Sequences are the most efficient, most flexible, and
              easiest-to-use of the library's data structures, provided that you
              never need to make an empty one: An empty sequence would contain
              no tokens, and so couldn't be passed as a macro argument. The
              other data structures covered here all have an empty
              representation.</p>
            <p>The facilities for manipulating sequences are all in the
              library's <tt class="docutils literal"><span class="pre">seq/</span></tt>
              subdirectory. They are summarized in Table A.5, where <tt class="docutils literal"><span

                  class="pre">t</span></tt> is the sequence <tt class="docutils literal"><span

                  class="pre">(</span></tt><em>t</em><sub>0</sub><tt class="docutils literal"><span

                  class="pre">)(</span></tt><em>t</em><sub>1</sub><tt class="docutils literal"><span

                  class="pre">)...(</span></tt><em>t</em><sub>k</sub><tt class="docutils literal"><span

                  class="pre">)</span></tt>. Where <em>s</em>, <em>r</em>, and
              <em>d</em> appear, they have a similar purpose to the <tt class="docutils literal"><span

                  class="pre">z</span></tt> parameters we discussed earlier (and
              suggested you ignore for now).</p>
            <table border="1" class="docutils">
              <caption>Preprocessor Sequence Operations</caption> <colgroup> <col

                  width="51%" /> <col width="49%" /> </colgroup>
              <thead valign="bottom">
                <tr>
                  <th>Expression</th>
                  <th>Result</th>
                </tr>
              </thead>
              <tbody valign="top">
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_CAT(t)</span></tt></td>
                  <td><em>t</em><sub>0</sub><em>t</em><sub>1</sub>...<em>t</em><sub>k</sub></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_ELEM(n,t)</span></tt></td>
                  <td><em>t</em><sub>n</sub></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_ENUM(t)</span></tt></td>
                  <td><em>t</em><sub>0</sub>, <em>t</em><sub>1</sub>, ...<em>t</em><sub>k</sub></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_FILTER(pred,data,t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">t</span></tt>
                    without the elements that don't satisfy <tt class="docutils literal"><span

                        class="pre">pred</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_FIRST_N(n,t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>n-1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_FOLD_LEFT(op,</span>
                      <span class="pre">x,</span> <span class="pre">t)</span></tt></td>
                  <td>...<tt class="docutils literal"><span class="pre">op(</span></tt><em>s</em><tt

                      class="docutils literal"><span class="pre">,op(</span></tt><em>s</em><tt

                      class="docutils literal"><span class="pre">,op(</span></tt><em>s</em><tt

                      class="docutils literal"><span class="pre">,x</span></tt>,<em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">),</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">),</span></tt><em>t</em><sub>2</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...</td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_FOLD_RIGHT(op,</span>
                      <span class="pre">x,</span> <span class="pre">t)</span></tt></td>
                  <td>...<tt class="docutils literal"><span class="pre">op(</span></tt><em>s</em><tt

                      class="docutils literal"><span class="pre">,op(</span></tt><em>s</em><tt

                      class="docutils literal"><span class="pre">,op(</span></tt><em>s</em><tt

                      class="docutils literal"><span class="pre">,x</span></tt>,<em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">),</span></tt><em>t</em><sub>k-1</sub><tt

                      class="docutils literal"><span class="pre">),</span></tt>
                    <em>t</em><sub>k-2</sub><tt class="docutils literal"><span class="pre">)</span></tt>...</td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_FOR_EACH(f,</span>
                      <span class="pre">x,</span> <span class="pre">t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">f(</span></tt><em>r</em><tt

                      class="docutils literal"><span class="pre">,</span> <span

                        class="pre">x,</span></tt><em>t</em><sub>0</sub><tt class="docutils literal"><span

                        class="pre">)</span> <span class="pre">f(</span></tt><em>r</em><tt

                      class="docutils literal"><span class="pre">,</span> <span

                        class="pre">x,</span></tt><em>t</em><sub>1</sub><tt class="docutils literal"><span

                        class="pre">)</span></tt>...<tt class="docutils literal"><span

                        class="pre">f(</span></tt><em>r</em><tt class="docutils literal"><span

                        class="pre">,</span> <span class="pre">x,</span></tt><em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_FOR_EACH_I(g,</span>
                      <span class="pre">x,</span> <span class="pre">t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">g(</span></tt><em>r</em><tt

                      class="docutils literal"><span class="pre">,</span> <span

                        class="pre">x,</span> <span class="pre">0,</span></tt>
                    <em>t</em><sub>0</sub><tt class="docutils literal"><span class="pre">)</span>
                      <span class="pre">g(</span></tt><em>r</em><tt class="docutils literal"><span

                        class="pre">,</span> <span class="pre">x,</span> <span

                        class="pre">1,</span></tt> <em>t</em><sub>1</sub><tt class="docutils literal"><span

                        class="pre">)</span></tt>... <tt class="docutils literal"><span

                        class="pre">g(</span></tt><em>r</em><tt class="docutils literal"><span

                        class="pre">,</span> <span class="pre">x,</span> <span

                        class="pre">k,</span></tt> <em>t</em><sub>k</sub><tt class="docutils literal"><span

                        class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_FOR_EACH_PRODUCT(h,</span>
                      <span class="pre">x,</span> <span class="pre">t)</span></tt></td>
                  <td>
                    <dl class="first last docutils">
                      <dt>Cartesian product—</dt>
                      <dd>see online docs</dd>
                    </dl>
                  </td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_INSERT(t,i,tokens)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>i-1</sub><tt

                      class="docutils literal"><span class="pre">)(tokens)</span>
                      <span class="pre">(</span></tt><em>t</em><sub>i</sub><tt class="docutils literal"><span

                        class="pre">)(</span></tt><em>t</em><sub>i+1</sub><tt class="docutils literal"><span

                        class="pre">)</span></tt>...<tt class="docutils literal"><span

                        class="pre">(</span></tt><em>t</em><sub>k</sub><tt class="docutils literal"><span

                        class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_POP_BACK(t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>k-1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_POP_FRONT(t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>2</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_PUSH_BACK(t,tokens)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">)(tokens)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_PUSH_FRONT(t,tokens)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(tokens)(</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_REMOVE(t,i)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>i-1</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>i+1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_REPLACE(t,i,tokens)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>i-1</sub><tt

                      class="docutils literal"><span class="pre">)(tokens)(</span></tt><em>t</em><sub>i+1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_REST_N(n,t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>n</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>n+1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_REVERSE(t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>k-1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_HEAD(t)</span></tt></td>
                  <td><em>t</em><sub>0</sub></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_TAIL(t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>2</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_SIZE(t)</span></tt></td>
                  <td><em>k+1</em></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_SUBSEQ(t,i,m)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>i</sub><tt

                      class="docutils literal"><span class="pre">)(</span></tt><em>t</em><sub>i+1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt>...<tt

                      class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>i+m-1</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_TO_ARRAY(t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>k+1</em>
                    <tt class="docutils literal"><span class="pre">,(</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt><em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...<em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">))</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_TO_TUPLE(t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt> <em>t</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...<em>t</em><sub>k</sub><tt

                      class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_TRANSFORM(f,</span>
                      <span class="pre">x,</span> <span class="pre">t)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(f(</span></tt><em>r</em><tt

                      class="docutils literal"><span class="pre">,x,</span></tt><em>t</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">))</span> <span

                        class="pre">(f(</span></tt><em>r</em><tt class="docutils literal"><span

                        class="pre">,x,</span></tt><em>t</em><sub>1</sub><tt class="docutils literal"><span

                        class="pre">))</span></tt>...<tt class="docutils literal"><span

                        class="pre">(f(</span></tt><em>r</em><tt class="docutils literal"><span

                        class="pre">,x,</span></tt><em>t</em><sub>k</sub><tt class="docutils literal"><span

                        class="pre">))</span></tt></td>
                </tr>
              </tbody>
            </table>
            <p>It's worth noting that while there is no upper limit on the
              length of a sequence, operations such as <tt class="docutils literal"><span

                  class="pre">BOOST_PP_SEQ_ELEM</span></tt> that take numeric
              arguments will only work with values up to 256.</p>
          </div>
          <div class="section" id="tuples">
            <h3><a name="tuples">A.4.5.2   Tuples</a></h3>
            <p>A <strong>tuple</strong> is a very simple data structure for
              which the library provides random access and a few other basic
              operations. A tuple takes the form of a parenthesized,
              comma-separated list of <em>macro arguments</em>. For example,
              this is a three-element tuple:</p>
            <pre class="literal-block">#define TUPLE3     (f(12), a + 1, foo)
</pre>
            <p>The operations in the library's <tt class="docutils literal"><span

                  class="pre">tuple/</span></tt> subdirectory can handle tuples
              of up to 25 elements. For example, a tuple's <tt class="docutils literal"><span

                  class="pre">N</span></tt>th element can be accessed via <tt class="docutils literal"><span

                  class="pre">BOOST_PP_TUPLE_ELEM</span></tt>, as follows:</p>
            <pre class="literal-block">                 // length  index  tuple 
BOOST_PP_TUPLE_ELEM(   3   ,  1  , TUPLE3)   // a + 1
</pre>
            <!-- @def gen_id(id = 'a', hdr = 'tuple'):
    example.wrap('''        #include <boost/preprocessor/%s.hpp>        int const %s = 0;        int const x =''' % (hdr,id), ';')
    compile('all', pop = 1)gen_id() -->
            <p>Notice that we had to pass the tuple's length as the second
              argument to <tt class="docutils literal"><span class="pre">BOOST_PP_TUPLE_ELEM</span></tt>;
              in fact, <em>all</em> tuple operations require explicit
              specification of the tuple's length. We're not going to summarize
              the other four operations in the "tuple" group here—you can
              consult the Preprocessor library's electronic documentation for
              more details. We note, however, that sequences can be transformed
              into tuples with <tt class="docutils literal"><span class="pre">BOOST_PP_SEQ_TO_TUPLE</span></tt>,
              and nonempty tuples can be transformed back into sequences with <tt

                class="docutils literal"><span class="pre">BOOST_PP_TUPLE_TO_SEQ</span></tt>.</p>
            <p>The greatest strength of tuples is that they conveniently take
              the same representation as a macro argument list:</p>
            <pre class="literal-block">#define FIRST_OF_THREE(a1,a2,a3)    a1
#define SECOND_OF_THREE(a1,a2,a3)   a2
#define THIRD_OF_THREE(a1,a2,a3)    a3

// uses tuple as an argument list
# define SELECT(selector, tuple)    <strong>selector tuple</strong>

SELECT(THIRD_OF_THREE, TUPLE3)   // foo
</pre>
            <!-- @gen_id('foo') --> </div>
          <div class="section" id="arrays">
            <h3><a name="arrays">A.4.5.3   Arrays</a></h3>
            <p>An <strong>array</strong> is just a tuple containing a
              non-negative integer and a tuple of that length:</p>
            <pre class="literal-block">#define ARRAY3     ( 3, TUPLE3 )
</pre>
            <p>Because an array carries its length around with it, the library's
              interface for operating on arrays is much more convenient than the
              one used for tuples:</p>
            <pre class="literal-block">BOOST_PP_ARRAY_ELEM(1, ARRAY3)     // a + 1
</pre>
            <!-- @gen_id(hdr = 'array')
del stack[-2:] -->
            <p>The facilities for manipulating arrays of up to 25 elements are
              all in the library's <tt class="docutils literal"><span class="pre">array/</span></tt>
              subdirectory. They are summarized in Table A.6, where <tt class="docutils literal"><span

                  class="pre">a</span></tt> is the array <tt class="docutils literal"><span

                  class="pre">(</span></tt><em>k</em><tt class="docutils literal"><span

                  class="pre">,</span> <span class="pre">(</span></tt><em>a</em><sub>0</sub><tt

                class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>1</sub><tt

                class="docutils literal"><span class="pre">,...</span></tt><em>a</em><sub>k-1</sub><tt

                class="docutils literal"><span class="pre">))</span></tt>.</p>
            <table border="1" class="docutils">
              <caption>Preprocessor Array Operations</caption> <colgroup> <col

                  width="52%" /> <col width="48%" /> </colgroup>
              <thead valign="bottom">
                <tr>
                  <th>Expression</th>
                  <th>Result</th>
                </tr>
              </thead>
              <tbody valign="top">
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_DATA(a)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>a</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>k-1</sub><tt class="docutils literal"><span class="pre">)</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_ELEM(i,a)</span></tt></td>
                  <td><em>a</em><sub>i</sub></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_INSERT(a,</span>
                      <span class="pre">i,</span> <span class="pre">tokens)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>k+1</em><tt

                      class="docutils literal"><span class="pre">,(</span></tt><em>a</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...<em>a</em><sub>i-1</sub><tt

                      class="docutils literal"><span class="pre">,</span> <span

                        class="pre">tokens,</span></tt> <em>a</em><sub>i</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>i+1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>k-1</sub><tt class="docutils literal"><span class="pre">))</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_POP_BACK(a)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>k-1</em><tt

                      class="docutils literal"><span class="pre">,(</span></tt><em>a</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>k-2</sub><tt class="docutils literal"><span class="pre">))</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_POP_FRONT(a)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>k-1</em><tt

                      class="docutils literal"><span class="pre">,(</span></tt><em>a</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>2</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>k-1</sub><tt class="docutils literal"><span class="pre">))</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_PUSH_BACK(a,</span>
                      <span class="pre">tokens)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>k+1</em><tt

                      class="docutils literal"><span class="pre">,(</span></tt><em>a</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>k-1</sub><tt class="docutils literal"><span class="pre">,</span>
                      <span class="pre">tokens))</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_PUSH_FRONT(a,</span>
                      <span class="pre">tokens)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>k+1</em><tt

                      class="docutils literal"><span class="pre">,(tokens,</span></tt>
                    <em>a</em><sub>1</sub><tt class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>2</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>k-1</sub><tt class="docutils literal"><span class="pre">))</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_REMOVE(a,</span>
                      <span class="pre">i)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>k-1</em><tt

                      class="docutils literal"><span class="pre">,(</span></tt><em>a</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>i-1</sub><tt class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>i+1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>k-1</sub><tt class="docutils literal"><span class="pre">))</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_REPLACE(a,</span>
                      <span class="pre">i,</span> <span class="pre">tokens)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>k</em><tt

                      class="docutils literal"><span class="pre">,(</span></tt><em>a</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>i-1</sub><tt class="docutils literal"><span class="pre">,</span>
                      <span class="pre">tokens,</span></tt> <em>a</em><sub>i+1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>k-1</sub><tt class="docutils literal"><span class="pre">))</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_REVERSE(a)</span></tt></td>
                  <td><tt class="docutils literal"><span class="pre">(</span></tt><em>k</em><tt

                      class="docutils literal"><span class="pre">,(</span></tt><em>a</em><sub>k-1</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>k-2</sub><tt

                      class="docutils literal"><span class="pre">,</span></tt>...
                    <em>a</em><sub>1</sub><tt class="docutils literal"><span class="pre">,</span></tt><em>a</em><sub>0</sub><tt

                      class="docutils literal"><span class="pre">))</span></tt></td>
                </tr>
                <tr>
                  <td><tt class="docutils literal"><span class="pre">BOOST_PP_ARRAY_SIZE(a)</span></tt></td>
                  <td><em>k</em></td>
                </tr>
              </tbody>
            </table>
          </div>
          <div class="section" id="lists">
            <h3><a name="lists">A.4.5.4   Lists</a></h3>
            <p>A <strong>list</strong> is a two-element tuple whose first
              element is the first element of the list, and whose second element
              is a list of the remaining elements, or <tt class="docutils literal"><span

                  class="pre">BOOST_PP_NIL</span></tt> if there are no remaining
              elements. Lists have access characteristics similar to those of a
              runtime linked list. Here is a three-element list:</p>
            <pre class="literal-block">#define LIST3     (<strong>f(12)</strong>, (<strong>a + 1</strong>, (<strong>foo</strong>, BOOST_PP_NIL)))
</pre>
            <!-- @ignore() -->
            <p>The facilities for manipulating lists are all in the library's <tt

                class="docutils literal"><span class="pre">list/</span></tt>
              subdirectory. Because the operations are a subset of those
              provided for sequences, we're not going to summarize them here—it
              should be easy to understand the list operations by reading the
              documentation on the basis of our coverage of sequences.</p>
            <p>Like sequences, lists have no fixed upper length bound. Unlike
              sequences, lists can also be empty. It's rare to need more than 25
              elements in a preprocessor data structure, and lists tend to be
              slower to manipulate and harder to read than any of the other
              structures, so they should normally be used only as a last resort.</p>
          </div>
        </div>
      </div>
      <div class="section" id="exercise">
        <h1><a name="exercise">A.5   Exercise</a></h1>
        <dl class="docutils">
          <dt>A-0</dt>
          <dd>Fully preprocessor-ize the <tt class="docutils literal"><span class="pre">tiny</span></tt>
            type sequence implemented in Chapter 5 so that all boilerplate code
            is eliminated and the maximum size of a <tt class="docutils literal"><span

                class="pre">tiny</span></tt> sequence can be adjusted by
            changing <tt class="docutils literal"><span class="pre">TINY_MAX_SIZE</span></tt>.</dd>
        </dl>
        <!-- on hold:
It isn't uncommon to need token-wise arithmetic operations forpurposes other than invoking Preprocessor Library repetitionmacros.  For example, let's write a metafunction to generate
function types from "signature" type sequences that specify thefunction's return and parameter types::  template <unsigned Size, class Signature>
  struct to_function_impl;  template <class Signature>  struct to_function
    : to_function_impl<mpl::size<Signature>::type, Signature>  {};The challenge now is to implement ``to_function_impl``.  For
``Size == 3``, an appropriate specialization might look like this::  template <class Signature>  struct to_function_impl<3,Signature>
  {      typedef mpl::begin<Signature>::type i0;      typedef mpl::deref<i0>::type        t0;
      typedef mpl::next<i0>::type         i1;      typedef mpl::deref<i1>::type        t1;      typedef mpl::next<i1>::type         i2;
      typedef mpl::deref<i2>::type        t2;      typedef t0 type(t1,t2);  };
A local macro to generate a single ``to_function_impl``specialization would look something like this:
.. parsed-literal::  #define to_function_impl_spec(size)                         \\    template <class Signature>                                    \\
    struct to_function_impl<3,Signature>                          \\    {                                                             \\        typedef mpl::begin<Signature>::type i0;                   \\        typedef mpl::deref<i0>::type        t0;                   \\
                                                                  \\        BOOST_PP_REPEAT_FROM_TO(1, size, to_function_t, ~)    \\                                                                  \\        typedef t0 type(BOOST_PP_ENUM_SHIFTED_PARAMS(size,t));    \\
    };  #define to_function_t(z, n, unused)                         \\    typedef mpl::next<BOOST_PP_CAT(i,\ **BOOST_PP_DEC(n)**)>::type      \\
        BOOST_PP_CAT(i,n);                                        \\                                                                  \\    typedef mpl::deref<BOOST_PP_CAT(i,n)>::type BOOST_PP_CAT(t,n);
We've used some new library macros above; here is a brief rundown:* ``BOOST_PP_REPEAT_FROM_TO`` is just like ``BOOST_PP_REPEAT``,  except that it accepts an initial repetition index.  Since every
  function has a return type, we don't need to worry about the case  where ``Size == 0``.* ``BOOST_PP_ENUM_SHIFTED_PARAMS`` is just like
  ``BOOST_PP_ENUM_PARAMS``, except that repetition indices start  at ``1`` instead of ``0``.* ``BOOST_PP_CAT`` implements token pasting; its two arguments are
  "glued" together into a single token.  Since this is a  general-purpose macro, it sits in ``cat.hpp`` at the top level of  the library's directory tree. [#paste]_
.. [#paste] The preprocessor's built-in token-pasting operator,   ``##``, often yields surprising results by taking effect before   its arguments have been expanded.  By contrast, ``BOOST_PP_CAT``   delays concatenation until after its arguments have been fully
   evaluated.* Finally, though it only performs trivial arithmetic,  ``BOOST_PP_DEC`` plays a crucial role in generating an
  appropriate prior iterator identifier for our own code in  ``to_function_t``.If we didn't have ``BOOST_PP_REPEAT_FROM_TO`` at our disposal in
the previous example, we might've had to use ``BOOST_PP_REPEAT``,which always starts iterating at ``0``.  Consequently``to_function_t`` would've been responsible for producing thedeclarations of ``i0`` and ``t0`` as well as those of the other
nested types.  To manage that, it would need a way to selectdifferent expansions depending on the value of ``n``.In its ``control/`` directory, the Preprocessor Library supplies a
macro ``BOOST_PP_IF(c,t,f)`` that fulfills a similar role to theone filled by ``mpl::if_``.  Rewriting the example accordingly, weget:
.. parsed-literal::  #define to_function_impl_spec(size)                         \\    template <class Signature>                                    \\
    struct to_function_impl<3,Signature>                          \\    {                                                             \\        BOOST_PP_REPEAT_FROM_TO(1, size, to_function_t, ~)    \\                                                                  \\
        typedef t0 type(BOOST_PP_ENUM_SHIFTED_PARAMS(size,t));    \\    };  #define to_function_t(z, n, unused)                         \\
    typedef BOOST_PP_IF(                                          \\                n,                                                \\                mpl::next<BOOST_PP_CAT(i,BOOST_PP_DEC(n))>::type, \\                typedef mpl::begin<Signature>::type i0;           \\
            )                                                     \\        BOOST_PP_CAT(i,n);                                        \\                                                                  \\    typedef mpl::deref<BOOST_PP_CAT(i,n)>::type BOOST_PP_CAT(t,n);
Although the formulation above will work, it does unnecessary workwhen ``n == 0``, evaluating the "true" branch of the conditionalonly to discard it. -->
      </div>
    </div>
    <hr class="docutils footer" />
    <div class="footer"> Generated on: 2005-10-17 19:34 UTC. Generated by <a class="reference"

        href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference"

        href="http://docutils.sourceforge.net/rst.html">reStructuredText</a>
      source. </div>
  </body>
</html>
<!--
     FILE ARCHIVED ON 19:59:10 Mar 30, 2013 AND RETRIEVED FROM THE     INTERNET ARCHIVE ON 21:06:19 May 19, 2015.     JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
     ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.     SECTION 108(a)(3)).-->