Subversion Repository Public Repository

Divide-Dependencies

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2018 NVIDIA Corporation. All rights reserved.



#ifndef MI_MAP_SET_INTERNAL_H

#define MI_MAP_SET_INTERNAL_H

/*
Copyright (C) 2009-2010 Electronic Arts, Inc.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1.  Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
2.  Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
3.  Neither the name of Electronic Arts, Inc. ("EA") nor the names of
    its contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

///////////////////////////////////////////////////////////////////////////////
// Written by Paul Pedriana.
//
// Refactored to be compliant with the PhysX data types by John W. Ratcliff
// on March 23, 2011
//////////////////////////////////////////////////////////////////////////////



#include "MiPlatformConfig.h"
#include <limits.h>
#include <stddef.h>
#include <new>

#pragma warning(push)
#pragma warning(disable:4512)

///////////////////////////////////////////////////////////////////////////////
// EASTL namespace
//
// We define this so that users that #include this config file can reference 
// these namespaces without seeing any other files that happen to use them.
///////////////////////////////////////////////////////////////////////////////

/// EA Standard Template Library
namespace mimp
{

///////////////////////////////////////////////////////////////////////////////
// EASTL_ALIGN_OF
//
// Determines the alignment of a type.
//
// Example usage:
//    size_t alignment = EASTL_ALIGN_OF(int);
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_ALIGN_OF
#if defined(__MWERKS__)
#define EASTL_ALIGN_OF(type) ((size_t)__alignof__(type))
#elif !defined(__GNUC__) || (__GNUC__ >= 3) // GCC 2.x doesn't do __alignof correctly all the time.
#define EASTL_ALIGN_OF __alignof
#else
#define EASTL_ALIGN_OF(type) ((size_t)offsetof(struct{ char c; type m; }, m))
#endif
#endif

///////////////////////////////////////////////////////////////////////////////
// EASTL_DEBUG
//
// Defined as an integer >= 0. Default is 1 for debug builds and 0 for 
// release builds. This define is also a master switch for the default value 
// of some other settings.
//
// Example usage:
//    #if EASTL_DEBUG
//       ...
//    #endif
//
///////////////////////////////////////////////////////////////////////////////

#if defined(_DEBUG)
        #define EASTL_DEBUG 1
#else
        #define EASTL_DEBUG 0
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_DEBUGPARAMS_LEVEL
//
// EASTL_DEBUGPARAMS_LEVEL controls what debug information is passed through to
// the allocator by default.
// This value may be defined by the user ... if not it will default to 1 for
// EA_DEBUG builds, otherwise 0.
//
//  0 - no debug information is passed through to allocator calls.
//  1 - 'name' is passed through to allocator calls.
//  2 - 'name', __FILE__, and __LINE__ are passed through to allocator calls.
//
// This parameter mirrors the equivalent parameter in the CoreAllocator package.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_DEBUGPARAMS_LEVEL
    #if EASTL_DEBUG
        #define EASTL_DEBUGPARAMS_LEVEL 2
    #else
        #define EASTL_DEBUGPARAMS_LEVEL 0
    #endif
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_NAME_ENABLED / EASTL_NAME / EASTL_NAME_VAL
//
// Used to wrap debug string names. In a release build, the definition 
// goes away. These are present to avoid release build compiler warnings 
// and to make code simpler.
//
// Example usage of EASTL_NAME:
//    // pName will defined away in a release build and thus prevent compiler warnings.
//    void allocator::set_name(const char* EASTL_NAME(pName))
//    {
//        #if EASTL_NAME_ENABLED
//            mpName = pName;
//        #endif
//    }
//
// Example usage of EASTL_NAME_VAL:
//    // "xxx" is defined to NULL in a release build.
//    vector<T, Allocator>::vector(const allocator_type& allocator = allocator_type(EASTL_NAME_VAL("xxx")));
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_NAME_ENABLED
    #define EASTL_NAME_ENABLED EASTL_DEBUG
#endif

#ifndef EASTL_NAME
    #if EASTL_NAME_ENABLED
        #define EASTL_NAME(x)      x
        #define EASTL_NAME_VAL(x)  x
    #else
        #define EASTL_NAME(x)
        #define EASTL_NAME_VAL(x) ((const char*)NULL)
    #endif
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_DEFAULT_NAME_PREFIX
//
// Defined as a string literal. Defaults to "EASTL".
// This define is used as the default name for EASTL where such a thing is
// referenced in EASTL. For example, if the user doesn't specify an allocator
// name for their deque, it is named "EASTL deque". However, you can override
// this to say "SuperBaseball deque" by changing EASTL_DEFAULT_NAME_PREFIX.
//
// Example usage (which is simply taken from how deque.h uses this define):
//     #ifndef EASTL_DEQUE_DEFAULT_NAME
//         #define EASTL_DEQUE_DEFAULT_NAME   EASTL_DEFAULT_NAME_PREFIX " deque"
//     #endif
//
#ifndef EASTL_DEFAULT_NAME_PREFIX
    #define EASTL_DEFAULT_NAME_PREFIX "EASTL"
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_ASSERT_ENABLED
//
// Defined as 0 or non-zero. Default is same as EASTL_DEBUG.
// If EASTL_ASSERT_ENABLED is non-zero, then asserts will be executed via 
// the assertion mechanism.
//
// Example usage:
//     #if EASTL_ASSERT_ENABLED
//         EASTL_ASSERT(v.size() > 17);
//     #endif
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_ASSERT_ENABLED
    #define EASTL_ASSERT_ENABLED EASTL_DEBUG
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
//
// Defined as 0 or non-zero. Default is same as EASTL_ASSERT_ENABLED.
// This is like EASTL_ASSERT_ENABLED, except it is for empty container 
// references. Sometime people like to be able to take a reference to 
// the front of the container, but not use it if the container is empty.
// In practice it's often easier and more efficient to do this than to write 
// extra code to check if the container is empty. 
//
// Example usage:
//     template <typename T, typename Allocator>
//     inline typename vector<T, Allocator>::reference
//     vector<T, Allocator>::front()
//     {
//         #if EASTL_ASSERT_ENABLED
//             EASTL_ASSERT(mpEnd > mpBegin);
//         #endif
// 
//         return *mpBegin;
//     }
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
    #define EASTL_EMPTY_REFERENCE_ASSERT_ENABLED EASTL_ASSERT_ENABLED
#endif



///////////////////////////////////////////////////////////////////////////////
// SetAssertionFailureFunction
//
// Allows the user to set a custom assertion failure mechanism.
//
// Example usage:
//     void Assert(const char* pExpression, void* pContext);
//     SetAssertionFailureFunction(Assert, this);
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_ASSERTION_FAILURE_DEFINED
    #define EASTL_ASSERTION_FAILURE_DEFINED

        typedef void (*EASTL_AssertionFailureFunction)(const char* pExpression, void* pContext);
         void SetAssertionFailureFunction(EASTL_AssertionFailureFunction pFunction, void* pContext);

        // These are the internal default functions that implement asserts.
         void AssertionFailure(const char* pExpression);
         void AssertionFailureFunctionDefault(const char* pExpression, void* pContext);
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_ASSERT
//
// Assertion macro. Can be overridden by user with a different value.
//
// Example usage:
//    EASTL_ASSERT(intVector.size() < 100);
//
///////////////////////////////////////////////////////////////////////////////

#define EASTL_ASSERT(expression)



///////////////////////////////////////////////////////////////////////////////
// EASTL_FAIL_MSG
//
// Failure macro. Can be overridden by user with a different value.
//
// Example usage:
//    EASTL_FAIL("detected error condition!");
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_FAIL_MSG
    #if EASTL_ASSERT_ENABLED
        #define EASTL_FAIL_MSG(message) (mimp::AssertionFailure(message))
    #else
        #define EASTL_FAIL_MSG(message)
    #endif
#endif




///////////////////////////////////////////////////////////////////////////////
// EASTL_CT_ASSERT / EASTL_CT_ASSERT_NAMED
//
// EASTL_CT_ASSERT is a macro for compile time assertion checks, useful for 
// validating *constant* expressions. The advantage over using EASTL_ASSERT 
// is that errors are caught at compile time instead of runtime.
//
// Example usage:
//     EASTL_CT_ASSERT(sizeof(mimp::MiU32 == 4));
//
///////////////////////////////////////////////////////////////////////////////

#if defined(EASTL_DEBUG) && !defined(EASTL_CT_ASSERT)
    template <bool>  struct EASTL_CT_ASSERTION_FAILURE;
    template <>      struct EASTL_CT_ASSERTION_FAILURE<true>{ enum { value = 1 }; }; // We create a specialization for true, but not for false.
    template <int x> struct EASTL_CT_ASSERTION_TEST{};

    #define EASTL_PREPROCESSOR_JOIN(a, b)  EASTL_PREPROCESSOR_JOIN1(a, b)
    #define EASTL_PREPROCESSOR_JOIN1(a, b) EASTL_PREPROCESSOR_JOIN2(a, b)
    #define EASTL_PREPROCESSOR_JOIN2(a, b) a##b

    #if defined(_MSC_VER)
        #define EASTL_CT_ASSERT(expression)  typedef EASTL_CT_ASSERTION_TEST< sizeof(EASTL_CT_ASSERTION_FAILURE< (bool)(expression) >)> EASTL_CT_ASSERT_FAILURE
    #elif defined(__ICL) || defined(__ICC)
        #define EASTL_CT_ASSERT(expression)  typedef char EASTL_PREPROCESSOR_JOIN(EASTL_CT_ASSERT_FAILURE_, __LINE__) [EASTL_CT_ASSERTION_FAILURE< (bool)(expression) >::value]
    #elif defined(__MWERKS__)
        #define EASTL_CT_ASSERT(expression)  enum { EASTL_PREPROCESSOR_JOIN(EASTL_CT_ASSERT_FAILURE_, __LINE__) = sizeof(EASTL_CT_ASSERTION_FAILURE< (bool)(expression) >) }
    #else // GCC, etc.
        #define EASTL_CT_ASSERT(expression)  typedef EASTL_CT_ASSERTION_TEST< sizeof(EASTL_CT_ASSERTION_FAILURE< (bool)(expression) >)> EASTL_PREPROCESSOR_JOIN1(EASTL_CT_ASSERT_FAILURE_, __LINE__)
    #endif
#else
    #define EASTL_CT_ASSERT(expression)
#endif


///////////////////////////////////////////////////////////////////////////////
// EASTL_ALLOCATOR_COPY_ENABLED
//
// Defined as 0 or 1. Default is 0 (disabled) until some future date.
// If enabled (1) then container operator= copies the allocator from the 
// source container. It ideally should be set to enabled but for backwards
// compatibility with older versions of EASTL it is currently set to 0.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_ALLOCATOR_COPY_ENABLED
    #define EASTL_ALLOCATOR_COPY_ENABLED 0
#endif

	///////////////////////////////////////////////////////////////////////////////
	// EASTL_FIXED_SIZE_TRACKING_ENABLED
	//
	// Defined as an integer >= 0. Default is same as EASTL_DEBUG.
	// If EASTL_FIXED_SIZE_TRACKING_ENABLED is enabled, then fixed
	// containers in debug builds track the max count of objects 
	// that have been in the container. This allows for the tuning
	// of fixed container sizes to their minimum required size.
	//
	///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_FIXED_SIZE_TRACKING_ENABLED
#define EASTL_FIXED_SIZE_TRACKING_ENABLED EASTL_DEBUG
#endif




///////////////////////////////////////////////////////////////////////////////
// EASTL_STRING_OPT_XXXX
//
// Enables some options / optimizations options that cause the string class 
// to behave slightly different from the C++ standard basic_string. These are 
// options whereby you can improve performance by avoiding operations that 
// in practice may never occur for you.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_STRING_OPT_CHAR_INIT
// Defined as 0 or 1. Default is 1.
// Defines if newly created characters are initialized to 0 or left
// as random values.
// The C++ string standard is to initialize chars to 0.
#define EASTL_STRING_OPT_CHAR_INIT 1
#endif

#ifndef EASTL_STRING_OPT_EXPLICIT_CTORS
// Defined as 0 or 1. Default is 0.
// Defines if we should implement explicity in constructors where the C++
// standard string does not. The advantage of enabling explicit constructors
// is that you can do this: string s = "hello"; in addition to string s("hello");
// The disadvantage of enabling explicity constructors is that there can be 
// silent conversions done which impede performance if the user isn't paying
// attention.
// C++ standard string ctors are not explicit.
#define EASTL_STRING_OPT_EXPLICIT_CTORS 0
#endif

#ifndef EASTL_STRING_OPT_LENGTH_ERRORS
// Defined as 0 or 1. Default is equal to EASTL_EXCEPTIONS_ENABLED.
// Defines if we check for string values going beyond kMaxSize 
// (a very large value) and throw exections if so.
// C++ standard strings are expected to do such checks.
#define EASTL_STRING_OPT_LENGTH_ERRORS 0
#endif

#ifndef EASTL_STRING_OPT_RANGE_ERRORS
// Defined as 0 or 1. Default is equal to EASTL_EXCEPTIONS_ENABLED.
// Defines if we check for out-of-bounds references to string
// positions and throw exceptions if so. Well-behaved code shouldn't 
// refence out-of-bounds positions and so shouldn't need these checks.
// C++ standard strings are expected to do such range checks.
#define EASTL_STRING_OPT_RANGE_ERRORS 0
#endif

#ifndef EASTL_STRING_OPT_ARGUMENT_ERRORS
// Defined as 0 or 1. Default is 0.
// Defines if we check for NULL ptr arguments passed to string 
// functions by the user and throw exceptions if so. Well-behaved code 
// shouldn't pass bad arguments and so shouldn't need these checks.
// Also, some users believe that strings should check for NULL pointers 
// in all their arguments and do no-ops if so. This is very debatable.
// C++ standard strings are not required to check for such argument errors.
#define EASTL_STRING_OPT_ARGUMENT_ERRORS 0
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_ABSTRACT_STRING_ENABLED
//
// Defined as 0 or 1. Default is 0 until abstract string is fully tested.
// Defines whether the proposed replacement for the string module is enabled.
// See bonus/abstract_string.h for more information.
//
#ifndef EASTL_ABSTRACT_STRING_ENABLED
#define EASTL_ABSTRACT_STRING_ENABLED 0
#endif




///////////////////////////////////////////////////////////////////////////////
// EASTL_BITSET_SIZE_T
//
// Defined as 0 or 1. Default is 1.
// Controls whether bitset uses size_t or size_t.
//
#ifndef EASTL_BITSET_SIZE_T
#define EASTL_BITSET_SIZE_T 1
#endif


///////////////////////////////////////////////////////////////////////////////
// EASTL_LIST_SIZE_CACHE
//
// Defined as 0 or 1. Default is 0.
// If defined as 1, the list and slist containers (and possibly any additional
// containers as well) keep a member mSize (or similar) variable which allows
// the size() member function to execute in constant time (a.k.a. O(1)). 
// There are debates on both sides as to whether it is better to have this 
// cached value or not, as having it entails some cost (memory and code).
// To consider: Make list size caching an optional template parameter.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_LIST_SIZE_CACHE
#define EASTL_LIST_SIZE_CACHE 0
#endif

#ifndef EASTL_SLIST_SIZE_CACHE
#define EASTL_SLIST_SIZE_CACHE 0
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_MAX_STACK_USAGE
//
// Defined as an integer greater than zero. Default is 4000.
// There are some places in EASTL where temporary objects are put on the 
// stack. A common example of this is in the implementation of container
// swap functions whereby a temporary copy of the container is made.
// There is a problem, however, if the size of the item created on the stack 
// is very large. This can happen with fixed-size containers, for example.
// The EASTL_MAX_STACK_USAGE define specifies the maximum amount of memory
// (in bytes) that the given platform/compiler will safely allow on the stack.
// Platforms such as Windows will generally allow larger values than embedded
// systems or console machines, but it is usually a good idea to stick with
// a max usage value that is portable across all platforms, lest the user be
// surprised when something breaks as it is ported to another platform.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_MAX_STACK_USAGE
#define EASTL_MAX_STACK_USAGE 4000
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_VA_COPY_ENABLED
//
// Defined as 0 or 1. Default is 1 for compilers that need it, 0 for others.
// Some compilers on some platforms implement va_list whereby its contents  
// are destroyed upon usage, even if passed by value to another function. 
// With these compilers you can use va_copy to restore the a va_list.
// Known compiler/platforms that destroy va_list contents upon usage include:
//     CodeWarrior on PowerPC
//     GCC on x86-64
// However, va_copy is part of the C99 standard and not part of earlier C and
// C++ standards. So not all compilers support it. VC++ doesn't support va_copy,
// but it turns out that VC++ doesn't need it on the platforms it supports.
// For example usage, see the EASTL string.h file.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_VA_COPY_ENABLED
#if defined(__MWERKS__) || (defined(__GNUC__) && (__GNUC__ >= 3) && (!defined(__i386__) || defined(__x86_64__)) && !defined(__ppc__) && !defined(__PPC__) && !defined(__PPC64__))
#define EASTL_VA_COPY_ENABLED 1
#else
#define EASTL_VA_COPY_ENABLED 0
#endif
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_LIST_PROXY_ENABLED
//
#if !defined(EASTL_LIST_PROXY_ENABLED)
// GCC with -fstrict-aliasing has bugs (or undocumented functionality in their 
// __may_alias__ implementation. The compiler gets confused about function signatures.
// VC8 (1400) doesn't need the proxy because it has built-in smart debugging capabilities.
#if defined(EASTL_DEBUG) && (!defined(__GNUC__) || defined(__SNC__)) && (!defined(_MSC_VER) || (_MSC_VER < 1400))
#define EASTL_LIST_PROXY_ENABLED 1
#define EASTL_LIST_PROXY_MAY_ALIAS EASTL_MAY_ALIAS
#else
#define EASTL_LIST_PROXY_ENABLED 0
#define EASTL_LIST_PROXY_MAY_ALIAS
#endif
#endif

#define EASTL_ITC_NS mimp

///////////////////////////////////////////////////////////////////////////////
// EASTL_VALIDATION_ENABLED
//
// Defined as an integer >= 0. Default is to be equal to EASTL_DEBUG.
// If nonzero, then a certain amount of automatic runtime validation is done.
// Runtime validation is not considered the same thing as asserting that user
// input values are valid. Validation refers to internal consistency checking
// of the validity of containers and their iterators. Validation checking is
// something that often involves significantly more than basic assertion 
// checking, and it may sometimes be desirable to disable it.
// This macro would generally be used internally by EASTL.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_VALIDATION_ENABLED
#define EASTL_VALIDATION_ENABLED EASTL_DEBUG
#endif




///////////////////////////////////////////////////////////////////////////////
// EASTL_VALIDATE_COMPARE
//
// Defined as EASTL_ASSERT or defined away. Default is EASTL_ASSERT if EASTL_VALIDATION_ENABLED is enabled.
// This is used to validate user-supplied comparison functions, particularly for sorting purposes.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_VALIDATE_COMPARE_ENABLED
#define EASTL_VALIDATE_COMPARE_ENABLED EASTL_VALIDATION_ENABLED
#endif

#if EASTL_VALIDATE_COMPARE_ENABLED
#define EASTL_VALIDATE_COMPARE EASTL_ASSERT
#else
#define EASTL_VALIDATE_COMPARE(expression)
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_VALIDATE_INTRUSIVE_LIST
//
// Defined as an integral value >= 0. Controls the amount of automatic validation
// done by intrusive_list. A value of 0 means no automatic validation is done.
// As of this writing, EASTL_VALIDATE_INTRUSIVE_LIST defaults to 0, as it makes
// the intrusive_list_node become a non-POD, which may be an issue for some code.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_VALIDATE_INTRUSIVE_LIST
#define EASTL_VALIDATE_INTRUSIVE_LIST 0
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_FORCE_INLINE
//
// Defined as a "force inline" expression or defined away.
// You generally don't need to use forced inlining with the Microsoft and 
// Metrowerks compilers, but you may need it with the GCC compiler (any version).
// 
// Example usage:
//     template <typename T, typename Allocator>
//     EASTL_FORCE_INLINE typename vector<T, Allocator>::size_type
//     vector<T, Allocator>::size() const
//        { return mpEnd - mpBegin; }
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_FORCE_INLINE
#define EASTL_FORCE_INLINE MI_INLINE
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_MAY_ALIAS
//
// Defined as a macro that wraps the GCC may_alias attribute. This attribute
// has no significance for VC++ because VC++ doesn't support the concept of 
// strict aliasing. Users should avoid writing code that breaks strict 
// aliasing rules; EASTL_MAY_ALIAS is for cases with no alternative.
//
// Example usage:
//    mimp::MiU32 value EASTL_MAY_ALIAS;
//
// Example usage:
//    typedef mimp::MiU32 EASTL_MAY_ALIAS value_type;
//    value_type value;
//
#if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 303)
#define EASTL_MAY_ALIAS __attribute__((__may_alias__))
#else
#define EASTL_MAY_ALIAS
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_LIKELY / EASTL_UNLIKELY
//
// Defined as a macro which gives a hint to the compiler for branch
// prediction. GCC gives you the ability to manually give a hint to 
// the compiler about the result of a comparison, though it's often
// best to compile shipping code with profiling feedback under both
// GCC (-fprofile-arcs) and VC++ (/LTCG:PGO, etc.). However, there 
// are times when you feel very sure that a boolean expression will
// usually evaluate to either true or false and can help the compiler
// by using an explicity directive...
//
// Example usage:
//    if(EASTL_LIKELY(a == 0)) // Tell the compiler that a will usually equal 0.
//       { ... }
//
// Example usage:
//    if(EASTL_UNLIKELY(a == 0)) // Tell the compiler that a will usually not equal 0.
//       { ... }
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_LIKELY
#if defined(__GNUC__) && (__GNUC__ >= 3)
#define EASTL_LIKELY(x)   __builtin_expect(!!(x), true)
#define EASTL_UNLIKELY(x) __builtin_expect(!!(x), false) 
#else
#define EASTL_LIKELY(x)   (x)
#define EASTL_UNLIKELY(x) (x)
#endif
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL_MINMAX_ENABLED
//
// Defined as 0 or 1; default is 1.
// Specifies whether the min and max algorithms are available. 
// It may be useful to disable the min and max algorithems because sometimes
// #defines for min and max exist which would collide with EASTL min and max.
// Note that there are already alternative versions of min and max in EASTL
// with the min_alt and max_alt functions. You can use these without colliding
// with min/max macros that may exist.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef EASTL_MINMAX_ENABLED
#define EASTL_MINMAX_ENABLED 1
#endif

///////////////////////////////////////////////////////////////////////////////
// EASTL_NOMINMAX
//
// Defined as 0 or 1; default is 1.
// MSVC++ has #defines for min/max which collide with the min/max algorithm
// declarations. If EASTL_NOMINMAX is defined as 1, then we undefine min and 
// max if they are #defined by an external library. This allows our min and 
// max definitions in algorithm.h to work as expected. An alternative to 
// the enabling of EASTL_NOMINMAX is to #define NOMINMAX in your project 
// settings if you are compiling for Windows.
// Note that this does not control the availability of the EASTL min and max 
// algorithms; the EASTL_MINMAX_ENABLED configuration parameter does that.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_NOMINMAX
#define EASTL_NOMINMAX 1
#endif



///////////////////////////////////////////////////////////////////////////////
// AddRef / Release
//
// AddRef and Release are used for "intrusive" reference counting. By the term
// "intrusive", we mean that the reference count is maintained by the object 
// and not by the user of the object. Given that an object implements referencing 
// counting, the user of the object needs to be able to increment and decrement
// that reference count. We do that via the venerable AddRef and Release functions
// which the object must supply. These defines here allow us to specify the name
// of the functions. They could just as well be defined to addref and delref or 
// IncRef and DecRef.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTLAddRef
#define EASTLAddRef AddRef
#endif

#ifndef EASTLRelease
#define EASTLRelease Release
#endif




///////////////////////////////////////////////////////////////////////////////
// EASTL_ALLOCATOR_EXPLICIT_ENABLED
//
// Defined as 0 or 1. Default is 0 for now but ideally would be changed to 
// 1 some day. It's 0 because setting it to 1 breaks some existing code.
// This option enables the allocator ctor to be explicit, which avoids
// some undesirable silent conversions, especially with the string class.
//
// Example usage:
//     class allocator
//     {
//     public:
//         EASTL_ALLOCATOR_EXPLICIT allocator(const char* pName);
//     };
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_ALLOCATOR_EXPLICIT_ENABLED
#define EASTL_ALLOCATOR_EXPLICIT_ENABLED 0
#endif

#if EASTL_ALLOCATOR_EXPLICIT_ENABLED
#define EASTL_ALLOCATOR_EXPLICIT explicit
#else
#define EASTL_ALLOCATOR_EXPLICIT 
#endif



///////////////////////////////////////////////////////////////////////////////
// EASTL allocator
//
// The EASTL allocator system allows you to redefine how memory is allocated
// via some defines that are set up here. In the container code, memory is 
// allocated via macros which expand to whatever the user has them set to 
// expand to. Given that there are multiple allocator systems available, 
// this system allows you to configure it to use whatever system you want,
// provided your system meets the requirements of this library. 
// The requirements are:
//
//     - Must be constructable via a const char* (name) parameter.
//       Some uses of allocators won't require this, however.
//     - Allocate a block of memory of size n and debug name string.
//     - Allocate a block of memory of size n, debug name string, 
//       alignment a, and offset o.
//     - Free memory allocated via either of the allocation functions above.
//     - Provide a default allocator instance which can be used if the user 
//       doesn't provide a specific one.
//
///////////////////////////////////////////////////////////////////////////////

// namespace mimp
// {
//     class allocator
//     {
//         allocator(const char* pName = NULL);
//
//         void* allocate(size_t n, int flags = 0);
//         void* allocate(size_t n, size_t alignment, size_t offset, int flags = 0);
//         void  deallocate(void* p, size_t n);
//
//         const char* get_name() const;
//         void        set_name(const char* pName);
//     };
//
//     allocator* GetDefaultAllocator(); // This is used for anonymous allocations.
// }

#ifndef EASTLAlloc // To consider: Instead of calling through pAllocator, just go directly to operator new, since that's what allocator does.
#define EASTLAlloc(allocator, n) (allocator).allocate(n);
#endif

#ifndef EASTLAllocFlags // To consider: Instead of calling through pAllocator, just go directly to operator new, since that's what allocator does.
#define EASTLAllocFlags(allocator, n, flags) (allocator).allocate(n, flags);
#endif

#ifndef EASTLAllocAligned
#define EASTLAllocAligned(allocator, n, alignment, offset) (allocator).allocate((n), (alignment), (offset))
#endif

#ifndef EASTLFree
#define EASTLFree(allocator, p, size) (allocator).deallocate((p), (size))
#endif

#ifndef EASTLAllocatorType
#define EASTLAllocatorType mimp::allocator
#endif

#ifndef EASTLAllocatorDefault
// EASTLAllocatorDefault returns the default allocator instance. This is not a global 
// allocator which implements all container allocations but is the allocator that is 
// used when EASTL needs to allocate memory internally. There are very few cases where 
// EASTL allocates memory internally, and in each of these it is for a sensible reason 
// that is documented to behave as such.
#define EASTLAllocatorDefault mimp::GetDefaultAllocator
#endif


	///////////////////////////////////////////////////////////////////////
	// integral_constant
	//
	// This is the base class for various type traits, as defined by the proposed
	// C++ standard. This is essentially a utility base class for defining properties
	// as both class constants (value) and as types (type).
	//
	template <typename T, T v>
	struct integral_constant
	{
		static const T value = v;
		typedef T value_type;
		typedef integral_constant<T, v> type;
	};


	///////////////////////////////////////////////////////////////////////
	// true_type / false_type
	//
	// These are commonly used types in the implementation of type_traits.
	// Other integral constant types can be defined, such as those based on int.
	//
	typedef integral_constant<bool, true>  true_type;
	typedef integral_constant<bool, false> false_type;



	///////////////////////////////////////////////////////////////////////
	// yes_type / no_type
	//
	// These are used as a utility to differentiate between two things.
	//
	typedef char yes_type;                      // sizeof(yes_type) == 1
	struct       no_type { char padding[8]; };  // sizeof(no_type)  != 1



	///////////////////////////////////////////////////////////////////////
	// type_select
	//
	// This is used to declare a type from one of two type options. 
	// The result is based on the condition type. This has certain uses
	// in template metaprogramming.
	//
	// Example usage:
	//    typedef ChosenType = type_select<is_integral<SomeType>::value, ChoiceAType, ChoiceBType>::type;
	//
	template <bool bCondition, class ConditionIsTrueType, class ConditionIsFalseType>
	struct type_select { typedef ConditionIsTrueType type; };

	template <typename ConditionIsTrueType, class ConditionIsFalseType>
	struct type_select<false, ConditionIsTrueType, ConditionIsFalseType> { typedef ConditionIsFalseType type; };



	///////////////////////////////////////////////////////////////////////
	// type_or
	//
	// This is a utility class for creating composite type traits.
	//
	template <bool b1, bool b2, bool b3 = false, bool b4 = false, bool b5 = false>
	struct type_or;

	template <bool b1, bool b2, bool b3, bool b4, bool b5>
	struct type_or { static const bool value = true; };

	template <> 
	struct type_or<false, false, false, false, false> { static const bool value = false; };



	///////////////////////////////////////////////////////////////////////
	// type_and
	//
	// This is a utility class for creating composite type traits.
	//
	template <bool b1, bool b2, bool b3 = true, bool b4 = true, bool b5 = true>
	struct type_and;

	template <bool b1, bool b2, bool b3, bool b4, bool b5>
	struct type_and{ static const bool value = false; };

	template <>
	struct type_and<true, true, true, true, true>{ static const bool value = true; };



	///////////////////////////////////////////////////////////////////////
	// type_equal
	//
	// This is a utility class for creating composite type traits.
	//
	template <int b1, int b2>
	struct type_equal{ static const bool value = (b1 == b2); };



	///////////////////////////////////////////////////////////////////////
	// type_not_equal
	//
	// This is a utility class for creating composite type traits.
	//
	template <int b1, int b2>
	struct type_not_equal{ static const bool value = (b1 != b2); };



	///////////////////////////////////////////////////////////////////////
	// type_not
	//
	// This is a utility class for creating composite type traits.
	//
	template <bool b>
	struct type_not{ static const bool value = true; };

	template <>
	struct type_not<true>{ static const bool value = false; };



	///////////////////////////////////////////////////////////////////////
	// empty
	//
	template <typename T>
	struct empty{ };



// The following files implement the type traits themselves.
#if defined(__GNUC__) && (__GNUC__ <= 2)
#else

///////////////////////////////////////////////////////////////////////////////
// EASTL/internal/type_fundamental.h
//
// Written and maintained by Paul Pedriana - 2005.
///////////////////////////////////////////////////////////////////////////////



	// The following properties or relations are defined here. If the given 
	// item is missing then it simply hasn't been implemented, at least not yet.


	///////////////////////////////////////////////////////////////////////
	// is_void
	//
	// is_void<T>::value == true if and only if T is one of the following types:
	//    [const][volatile] void
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct is_void : public false_type{};

	template <> struct is_void<void> : public true_type{};
	template <> struct is_void<void const> : public true_type{};
	template <> struct is_void<void volatile> : public true_type{};
	template <> struct is_void<void const volatile> : public true_type{};


	///////////////////////////////////////////////////////////////////////
	// is_integral
	//
	// is_integral<T>::value == true if and only if T  is one of the following types:
	//    [const] [volatile] bool
	//    [const] [volatile] char
	//    [const] [volatile] signed char
	//    [const] [volatile] unsigned char
	//    [const] [volatile] wchar_t
	//    [const] [volatile] short
	//    [const] [volatile] int
	//    [const] [volatile] long
	//    [const] [volatile] long long
	//    [const] [volatile] unsigned short
	//    [const] [volatile] unsigned int
	//    [const] [volatile] unsigned long
	//    [const] [volatile] unsigned long long
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct is_integral : public false_type{};

	// To do: Need to define volatile and const volatile versions of these.
	template <> struct is_integral<unsigned char>            : public true_type{};
	template <> struct is_integral<const unsigned char>      : public true_type{};
	template <> struct is_integral<unsigned short>           : public true_type{};
	template <> struct is_integral<const unsigned short>     : public true_type{};
	template <> struct is_integral<unsigned int>             : public true_type{};
	template <> struct is_integral<const unsigned int>       : public true_type{};
	template <> struct is_integral<unsigned long>            : public true_type{};
	template <> struct is_integral<const unsigned long>      : public true_type{};
	template <> struct is_integral<unsigned long long>       : public true_type{};
	template <> struct is_integral<const unsigned long long> : public true_type{};

	template <> struct is_integral<signed char>              : public true_type{};
	template <> struct is_integral<const signed char>        : public true_type{};
	template <> struct is_integral<signed short>             : public true_type{};
	template <> struct is_integral<const signed short>       : public true_type{};
	template <> struct is_integral<signed int>               : public true_type{};
	template <> struct is_integral<const signed int>         : public true_type{};
	template <> struct is_integral<signed long>              : public true_type{};
	template <> struct is_integral<const signed long>        : public true_type{};
	template <> struct is_integral<signed long long>         : public true_type{};
	template <> struct is_integral<const signed long long>   : public true_type{};

	template <> struct is_integral<bool>            : public true_type{};
	template <> struct is_integral<const bool>      : public true_type{};
	template <> struct is_integral<char>            : public true_type{};
	template <> struct is_integral<const char>      : public true_type{};
#ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type...
	template <> struct is_integral<wchar_t>         : public true_type{};
	template <> struct is_integral<const wchar_t>   : public true_type{};
#endif

	///////////////////////////////////////////////////////////////////////
	// is_floating_point
	//
	// is_floating_point<T>::value == true if and only if T is one of the following types:
	//    [const] [volatile] float
	//    [const] [volatile] double
	//    [const] [volatile] long double
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct is_floating_point : public false_type{};

	// To do: Need to define volatile and const volatile versions of these.
	template <> struct is_floating_point<float>             : public true_type{};
	template <> struct is_floating_point<const float>       : public true_type{};
	template <> struct is_floating_point<double>            : public true_type{};
	template <> struct is_floating_point<const double>      : public true_type{};
	template <> struct is_floating_point<long double>       : public true_type{};
	template <> struct is_floating_point<const long double> : public true_type{};



	///////////////////////////////////////////////////////////////////////
	// is_arithmetic
	//
	// is_arithmetic<T>::value == true if and only if:
	//    is_floating_point<T>::value == true, or
	//    is_integral<T>::value == true
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T> 
	struct is_arithmetic : public integral_constant<bool,
		is_integral<T>::value || is_floating_point<T>::value
	>{};


	///////////////////////////////////////////////////////////////////////
	// is_fundamental
	//
	// is_fundamental<T>::value == true if and only if:
	//    is_floating_point<T>::value == true, or
	//    is_integral<T>::value == true, or
	//    is_void<T>::value == true
	///////////////////////////////////////////////////////////////////////
	template <typename T> 
	struct is_fundamental : public integral_constant<bool,
		is_void<T>::value || is_integral<T>::value || is_floating_point<T>::value
	>{};

#endif

///////////////////////////////////////////////////////////////////////////////
// EASTL/internal/type_transformations.h
// Written and maintained by Paul Pedriana - 2005
///////////////////////////////////////////////////////////////////////////////



	// The following transformations are defined here. If the given item 
	// is missing then it simply hasn't been implemented, at least not yet.
	//    add_unsigned
	//    add_signed
	//    remove_const
	//    remove_volatile
	//    remove_cv
	//    add_const
	//    add_volatile
	//    add_cv
	//    remove_reference
	//    add_reference
	//    remove_extent
	//    remove_all_extents
	//    remove_pointer
	//    add_pointer
	//    aligned_storage


	///////////////////////////////////////////////////////////////////////
	// add_signed
	//
	// Adds signed-ness to the given type. 
	// Modifies only integral values; has no effect on others.
	// add_signed<int>::type is int
	// add_signed<unsigned int>::type is int
	//
	///////////////////////////////////////////////////////////////////////

	template<class T>
	struct add_signed
	{ typedef T type; };

	template<>
	struct add_signed<unsigned char>
	{ typedef signed char type; };

#if (defined(CHAR_MAX) && defined(UCHAR_MAX) && (CHAR_MAX == UCHAR_MAX)) // If char is unsigned (which is usually not the case)...
	template<>
	struct add_signed<char>
	{ typedef signed char type; };
#endif

	template<>
	struct add_signed<unsigned short>
	{ typedef short type; };

	template<>
	struct add_signed<unsigned int>
	{ typedef int type; };

	template<>
	struct add_signed<unsigned long>
	{ typedef long type; };

	template<>
	struct add_signed<unsigned long long>
	{ typedef long long type; };

#ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type...
#if (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 4294967295U)) // If wchar_t is a 32 bit unsigned value...
	template<>
	struct add_signed<wchar_t>
	{ typedef int32_t type; };
#elif (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 65535)) // If wchar_t is a 16 bit unsigned value...
	template<>
	struct add_signed<wchar_t>
	{ typedef int16_t type; };
#endif
#endif



	///////////////////////////////////////////////////////////////////////
	// add_unsigned
	//
	// Adds unsigned-ness to the given type. 
	// Modifies only integral values; has no effect on others.
	// add_unsigned<int>::type is unsigned int
	// add_unsigned<unsigned int>::type is unsigned int
	//
	///////////////////////////////////////////////////////////////////////

	template<class T>
	struct add_unsigned
	{ typedef T type; };

	template<>
	struct add_unsigned<signed char>
	{ typedef unsigned char type; };

#if (defined(CHAR_MAX) && defined(SCHAR_MAX) && (CHAR_MAX == SCHAR_MAX)) // If char is signed (which is usually so)...
	template<>
	struct add_unsigned<char>
	{ typedef unsigned char type; };
#endif

	template<>
	struct add_unsigned<short>
	{ typedef unsigned short type; };

	template<>
	struct add_unsigned<int>
	{ typedef unsigned int type; };

	template<>
	struct add_unsigned<long>
	{ typedef unsigned long type; };

	template<>
	struct add_unsigned<long long>
	{ typedef unsigned long long type; };

#ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type...
#if (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 2147483647)) // If wchar_t is a 32 bit signed value...
	template<>
	struct add_unsigned<wchar_t>
	{ typedef mimp::MiU32 type; };
#elif (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 32767)) // If wchar_t is a 16 bit signed value...
	template<>
	struct add_unsigned<wchar_t>
	{ typedef MiU16 type; };
#endif
#endif

	///////////////////////////////////////////////////////////////////////
	// remove_cv
	//
	// Remove const and volatile from a type.
	//
	// The remove_cv transformation trait removes top-level const and/or volatile 
	// qualification (if any) from the type to which it is applied. For a given type T, 
	// remove_cv<T const volatile>::type is equivalent to T. For example, 
	// remove_cv<char* volatile>::type is equivalent to char*, while remove_cv<const char*>::type 
	// is equivalent to const char*. In the latter case, the const qualifier modifies 
	// char, not *, and is therefore not at the top level.
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct remove_cv_imp{};
	template <typename T> struct remove_cv_imp<T*>                { typedef T unqualified_type; };
	template <typename T> struct remove_cv_imp<const T*>          { typedef T unqualified_type; };
	template <typename T> struct remove_cv_imp<volatile T*>       { typedef T unqualified_type; };
	template <typename T> struct remove_cv_imp<const volatile T*> { typedef T unqualified_type; };

	template <typename T> struct remove_cv{ typedef typename remove_cv_imp<T*>::unqualified_type type; };
	template <typename T> struct remove_cv<T&>{ typedef T& type; }; // References are automatically not const nor volatile. See section 8.3.2p1 of the C++ standard.

	template <typename T, size_t N> struct remove_cv<T const[N]>         { typedef T type[N]; };
	template <typename T, size_t N> struct remove_cv<T volatile[N]>      { typedef T type[N]; };
	template <typename T, size_t N> struct remove_cv<T const volatile[N]>{ typedef T type[N]; };



	///////////////////////////////////////////////////////////////////////
	// add_reference
	//
	// Add reference to a type.
	//
	// The add_reference transformation trait adds a level of indirection 
	// by reference to the type to which it is applied. For a given type T, 
	// add_reference<T>::type is equivalent to T& if is_reference<T>::value == false, 
	// and T otherwise.
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T>
	struct add_reference_impl{ typedef T& type; };

	template <typename T>
	struct add_reference_impl<T&>{ typedef T& type; };

	template <>
	struct add_reference_impl<void>{ typedef void type; };

	template <typename T>
	struct add_reference { typedef typename add_reference_impl<T>::type type; };


///////////////////////////////////////////////////////////////////////////////
// EASTL/internal/type_properties.h
// Written and maintained by Paul Pedriana - 2005.
///////////////////////////////////////////////////////////////////////////////





	// The following properties or relations are defined here. If the given 
	// item is missing then it simply hasn't been implemented, at least not yet.

	///////////////////////////////////////////////////////////////////////
	// is_const
	//
	// is_const<T>::value == true if and only if T has const-qualification.
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct is_const_value                    : public false_type{};
	template <typename T> struct is_const_value<const T*>          : public true_type{};
	template <typename T> struct is_const_value<const volatile T*> : public true_type{};

	template <typename T> struct is_const : public is_const_value<T*>{};
	template <typename T> struct is_const<T&> : public false_type{}; // Note here that T is const, not the reference to T. So is_const is false. See section 8.3.2p1 of the C++ standard.



	///////////////////////////////////////////////////////////////////////
	// is_volatile
	//
	// is_volatile<T>::value == true  if and only if T has volatile-qualification.
	//
	///////////////////////////////////////////////////////////////////////

	template <typename T> struct is_volatile_value                    : public false_type{};
	template <typename T> struct is_volatile_value<volatile T*>       : public true_type{};
	template <typename T> struct is_volatile_value<const volatile T*> : public true_type{};

	template <typename T> struct is_volatile : public is_volatile_value<T*>{};
	template <typename T> struct is_volatile<T&> : public false_type{}; // Note here that T is volatile, not the reference to T. So is_const is false. See section 8.3.2p1 of the C++ standard.



	///////////////////////////////////////////////////////////////////////
	// is_abstract
	//
	// is_abstract<T>::value == true if and only if T is a class or struct 
	// that has at least one pure virtual function. is_abstract may only 
	// be applied to complete types.
	//
	///////////////////////////////////////////////////////////////////////

	// Not implemented yet.



	///////////////////////////////////////////////////////////////////////
	// is_signed
	//
	// is_signed<T>::value == true if and only if T is one of the following types:
	//    [const] [volatile] char (maybe)
	//    [const] [volatile] signed char
	//    [const] [volatile] short
	//    [const] [volatile] int
	//    [const] [volatile] long
	//    [const] [volatile] long long
	// 
	// Used to determine if a integral type is signed or unsigned.
	// Given that there are some user-made classes which emulate integral
	// types, we provide the EASTL_DECLARE_SIGNED macro to allow you to 
	// set a given class to be identified as a signed type.
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct is_signed : public false_type{};

	template <> struct is_signed<signed char>              : public true_type{};
	template <> struct is_signed<const signed char>        : public true_type{};
	template <> struct is_signed<signed short>             : public true_type{};
	template <> struct is_signed<const signed short>       : public true_type{};
	template <> struct is_signed<signed int>               : public true_type{};
	template <> struct is_signed<const signed int>         : public true_type{};
	template <> struct is_signed<signed long>              : public true_type{};
	template <> struct is_signed<const signed long>        : public true_type{};
	template <> struct is_signed<signed long long>         : public true_type{};
	template <> struct is_signed<const signed long long>   : public true_type{};

#if (CHAR_MAX == SCHAR_MAX)
	template <> struct is_signed<char>            : public true_type{};
	template <> struct is_signed<const char>      : public true_type{};
#endif
#ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type...
#if defined(__WCHAR_MAX__) && ((__WCHAR_MAX__ == 2147483647) || (__WCHAR_MAX__ == 32767)) // GCC defines __WCHAR_MAX__ for most platforms.
	template <> struct is_signed<wchar_t>         : public true_type{};
	template <> struct is_signed<const wchar_t>   : public true_type{};
#endif
#endif

#define EASTL_DECLARE_SIGNED(T) namespace mimp{ template <> struct is_signed<T> : public true_type{}; template <> struct is_signed<const T> : public true_type{}; }



	///////////////////////////////////////////////////////////////////////
	// is_unsigned
	//
	// is_unsigned<T>::value == true if and only if T is one of the following types:
	//    [const] [volatile] char (maybe)
	//    [const] [volatile] unsigned char
	//    [const] [volatile] unsigned short
	//    [const] [volatile] unsigned int
	//    [const] [volatile] unsigned long
	//    [const] [volatile] unsigned long long
	//
	// Used to determine if a integral type is signed or unsigned. 
	// Given that there are some user-made classes which emulate integral
	// types, we provide the EASTL_DECLARE_UNSIGNED macro to allow you to 
	// set a given class to be identified as an unsigned type.
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct is_unsigned : public false_type{};

	template <> struct is_unsigned<unsigned char>              : public true_type{};
	template <> struct is_unsigned<const unsigned char>        : public true_type{};
	template <> struct is_unsigned<unsigned short>             : public true_type{};
	template <> struct is_unsigned<const unsigned short>       : public true_type{};
	template <> struct is_unsigned<unsigned int>               : public true_type{};
	template <> struct is_unsigned<const unsigned int>         : public true_type{};
	template <> struct is_unsigned<unsigned long>              : public true_type{};
	template <> struct is_unsigned<const unsigned long>        : public true_type{};
	template <> struct is_unsigned<unsigned long long>         : public true_type{};
	template <> struct is_unsigned<const unsigned long long>   : public true_type{};

#if (CHAR_MAX == UCHAR_MAX)
	template <> struct is_unsigned<char>            : public true_type{};
	template <> struct is_unsigned<const char>      : public true_type{};
#endif
#ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type...
#if defined(_MSC_VER) || (defined(__WCHAR_MAX__) && ((__WCHAR_MAX__ == 4294967295U) || (__WCHAR_MAX__ == 65535))) // GCC defines __WCHAR_MAX__ for most platforms.
	template <> struct is_unsigned<wchar_t>         : public true_type{};
	template <> struct is_unsigned<const wchar_t>   : public true_type{};
#endif
#endif

#define EASTL_DECLARE_UNSIGNED(T) namespace mimp{ template <> struct is_unsigned<T> : public true_type{}; template <> struct is_unsigned<const T> : public true_type{}; }



	///////////////////////////////////////////////////////////////////////
	// alignment_of
	//
	// alignment_of<T>::value is an integral value representing, in bytes, 
	// the memory alignment of objects of type T.
	//
	// alignment_of may only be applied to complete types.
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T>
	struct alignment_of_value{ static const size_t value = EASTL_ALIGN_OF(T); };

	template <typename T>
	struct alignment_of : public integral_constant<size_t, alignment_of_value<T>::value>{};



	///////////////////////////////////////////////////////////////////////
	// is_aligned
	//
	// Defined as true if the type has alignment requirements greater 
	// than default alignment, which is taken to be 8. This allows for 
	// doing specialized object allocation and placement for such types.
	///////////////////////////////////////////////////////////////////////
	template <typename T>
	struct is_aligned_value{ static const bool value = (EASTL_ALIGN_OF(T) > 8); };

	template <typename T> 
	struct is_aligned : public integral_constant<bool, is_aligned_value<T>::value>{};



	///////////////////////////////////////////////////////////////////////
	// rank
	//
	// rank<T>::value is an integral value representing the number of 
	// dimensions possessed by an array type. For example, given a 
	// multi-dimensional array type T[M][N], std::tr1::rank<T[M][N]>::value == 2. 
	// For a given non-array type T, std::tr1::rank<T>::value == 0.
	//
	///////////////////////////////////////////////////////////////////////

	// Not implemented yet.



	///////////////////////////////////////////////////////////////////////
	// extent
	//
	// extent<T, I>::value is an integral type representing the number of 
	// elements in the Ith dimension of array type T.
	// 
	// For a given array type T[N], std::tr1::extent<T[N]>::value == N.
	// For a given multi-dimensional array type T[M][N], std::tr1::extent<T[M][N], 0>::value == N.
	// For a given multi-dimensional array type T[M][N], std::tr1::extent<T[M][N], 1>::value == M.
	// For a given array type T and a given dimension I where I >= rank<T>::value, std::tr1::extent<T, I>::value == 0.
	// For a given array type of unknown extent T[], std::tr1::extent<T[], 0>::value == 0.
	// For a given non-array type T and an arbitrary dimension I, std::tr1::extent<T, I>::value == 0.
	// 
	///////////////////////////////////////////////////////////////////////

	// Not implemented yet.



	///////////////////////////////////////////////////////////////////////
	// is_base_of
	//
	// Given two (possibly identical) types Base and Derived, is_base_of<Base, Derived>::value == true 
	// if and only if Base is a direct or indirect base class of Derived, 
	// or Base and Derived are the same type.
	//
	// is_base_of may only be applied to complete types.
	//
	///////////////////////////////////////////////////////////////////////

	// Not implemented yet.



///////////////////////////////////////////////////////////////////////////////
// EASTL/internal/type_compound.h
// Written and maintained by Paul Pedriana - 2005.
///////////////////////////////////////////////////////////////////////////////



	// The following properties or relations are defined here. If the given 
	// item is missing then it simply hasn't been implemented, at least not yet.
	//   is_array
	//   is_pointer
	//   is_reference
	//   is_member_object_pointer
	//   is_member_function_pointer
	//   is_member_pointer
	//   is_enum
	//   is_union
	//   is_class
	//   is_polymorphic
	//   is_function
	//   is_object
	//   is_scalar
	//   is_compound
	//   is_same
	//   is_convertible

	///////////////////////////////////////////////////////////////////////
	// is_array
	//
	// is_array<T>::value == true if and only if T is an array type.
	// As of this writing, the SNC compiler (EDG-based) doesn't compile
	// the code below and says that returning an array is illegal.
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T>
	T (*is_array_tester1(empty<T>))(empty<T>);
	char is_array_tester1(...);     // May need to use __cdecl under VC++.

	template <typename T>
	no_type  is_array_tester2(T(*)(empty<T>));
	yes_type is_array_tester2(...); // May need to use __cdecl under VC++.

	template <typename T>
	struct is_array_helper {
		static empty<T> emptyInstance;
	};

	template <typename T> 
	struct is_array : public integral_constant<bool,
		sizeof(is_array_tester2(is_array_tester1(is_array_helper<T>::emptyInstance))) == 1
	>{};



	///////////////////////////////////////////////////////////////////////
	// is_reference
	//
	// is_reference<T>::value == true if and only if T is a reference type. 
	// This category includes reference to function types.
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct is_reference : public false_type{};
	template <typename T> struct is_reference<T&> : public true_type{};



	///////////////////////////////////////////////////////////////////////
	// is_member_function_pointer
	//
	// is_member_function_pointer<T>::value == true if and only if T is a 
	// pointer to member function type.
	//
	///////////////////////////////////////////////////////////////////////
	// We detect member functions with 0 to N arguments. We can extend this
	// for additional arguments if necessary.
	// To do: Make volatile and const volatile versions of these in addition to non-const and const.
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct is_mem_fun_pointer_value : public false_type{};
	template <typename R, typename T> struct is_mem_fun_pointer_value<R (T::*)()> : public true_type{};
	template <typename R, typename T> struct is_mem_fun_pointer_value<R (T::*)() const> : public true_type{};
	template <typename R, typename T, typename Arg0> struct is_mem_fun_pointer_value<R (T::*)(Arg0)> : public true_type{};
	template <typename R, typename T, typename Arg0> struct is_mem_fun_pointer_value<R (T::*)(Arg0) const> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1)> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1) const> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2)> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2) const> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2, typename Arg3> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2, Arg3)> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2, typename Arg3> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2, Arg3) const> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2, Arg3, Arg4)> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2, Arg3, Arg4) const> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5) const> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) const> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename Arg7> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)> : public true_type{};
	template <typename R, typename T, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename Arg7> struct is_mem_fun_pointer_value<R (T::*)(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) const> : public true_type{};

	template <typename T> 
	struct is_member_function_pointer : public integral_constant<bool, is_mem_fun_pointer_value<T>::value>{};


	///////////////////////////////////////////////////////////////////////
	// is_member_pointer
	//
	// is_member_pointer<T>::value == true if and only if:
	//    is_member_object_pointer<T>::value == true, or
	//    is_member_function_pointer<T>::value == true
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T> 
	struct is_member_pointer : public integral_constant<bool, is_member_function_pointer<T>::value>{};

	template <typename T, typename U> struct is_member_pointer<U T::*> : public true_type{};




	///////////////////////////////////////////////////////////////////////
	// is_pointer
	//
	// is_pointer<T>::value == true if and only if T is a pointer type. 
	// This category includes function pointer types, but not pointer to 
	// member types.
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct is_pointer_helper : public false_type{};

	template <typename T> struct is_pointer_helper<T*>                : public true_type{};
	template <typename T> struct is_pointer_helper<T* const>          : public true_type{};
	template <typename T> struct is_pointer_helper<T* volatile>       : public true_type{};
	template <typename T> struct is_pointer_helper<T* const volatile> : public true_type{};

	template <typename T>
	struct is_pointer_value : public type_and<is_pointer_helper<T>::value, type_not<is_member_pointer<T>::value>::value> {};

	template <typename T> 
	struct is_pointer : public integral_constant<bool, is_pointer_value<T>::value>{};



	///////////////////////////////////////////////////////////////////////
	// is_same
	//
	// Given two (possibly identical) types T and U, is_same<T, U>::value == true 
	// if and only if T and U are the same type.
	//
	///////////////////////////////////////////////////////////////////////
	template<typename T, typename U>
	struct is_same : public false_type { };

	template<typename T>
	struct is_same<T, T> : public true_type { };


	///////////////////////////////////////////////////////////////////////
	// is_convertible
	//
	// Given two (possible identical) types From and To, is_convertible<From, To>::value == true 
	// if and only if an lvalue of type From can be implicitly converted to type To, 
	// or is_void<To>::value == true
	//
	// is_convertible may only be applied to complete types.
	// Type To may not be an abstract type. 
	// If the conversion is ambiguous, the program is ill-formed. 
	// If either or both of From and To are class types, and the conversion would invoke 
	// non-public member functions of either From or To (such as a private constructor of To, 
	// or a private conversion operator of From), the program is ill-formed.
	//
	// Note that without compiler help, both is_convertible and is_base 
	// can produce compiler errors if the conversion is ambiguous. 
	// Example:
	//    struct A {};
	//    struct B : A {};
	//    struct C : A {};
	//    struct D : B, C {};
	//    is_convertible<D*, A*>::value; // Generates compiler error.
	///////////////////////////////////////////////////////////////////////
#if !defined(__GNUC__) || (__GNUC__ >= 3) // GCC 2.x doesn't like the code below.
	template <typename From, typename To, bool is_from_void = false, bool is_to_void = false>
	struct is_convertible_helper {
		static yes_type Test(To);  // May need to use __cdecl under VC++.
		static no_type  Test(...); // May need to use __cdecl under VC++.
		static From from;
		typedef integral_constant<bool, sizeof(Test(from)) == sizeof(yes_type)> result;
	};

	// void is not convertible to non-void
	template <typename From, typename To>
	struct is_convertible_helper<From, To, true, false> { typedef false_type result; };

	// Anything is convertible to void
	template <typename From, typename To, bool is_from_void>
	struct is_convertible_helper<From, To, is_from_void, true> { typedef true_type result; };

	template <typename From, typename To>
	struct is_convertible : public is_convertible_helper<From, To, is_void<From>::value, is_void<To>::value>::result {};

#else
	template <typename From, typename To>
	struct is_convertible : public false_type{};
#endif


	///////////////////////////////////////////////////////////////////////
	// is_union
	//
	// is_union<T>::value == true if and only if T is a union type.
	//
	// There is no way to tell if a type is a union without compiler help.
	// As of this writing, only Metrowerks v8+ supports such functionality
	// via 'msl::is_union<T>::value'. The user can force something to be 
	// evaluated as a union via EASTL_DECLARE_UNION.
	///////////////////////////////////////////////////////////////////////
	template <typename T> struct is_union : public false_type{};

#define EASTL_DECLARE_UNION(T) namespace mimp{ template <> struct is_union<T> : public true_type{}; template <> struct is_union<const T> : public true_type{}; }




	///////////////////////////////////////////////////////////////////////
	// is_class
	//
	// is_class<T>::value == true if and only if T is a class or struct 
	// type (and not a union type).
	//
	// Without specific compiler help, it is not possible to 
	// distinguish between unions and classes. As a result, is_class
	// will erroneously evaluate to true for union types.
	///////////////////////////////////////////////////////////////////////
#if defined(__MWERKS__)
	// To do: Switch this to use msl_utility type traits.
	template <typename T> 
	struct is_class : public false_type{};
#elif !defined(__GNUC__) || (((__GNUC__ * 100) + __GNUC_MINOR__) >= 304) // Not GCC or GCC 3.4+
	template <typename U> static yes_type is_class_helper(void (U::*)());
	template <typename U> static no_type  is_class_helper(...);

	template <typename T> 
	struct is_class : public integral_constant<bool,
		sizeof(is_class_helper<T>(0)) == sizeof(yes_type) && !is_union<T>::value
	>{};
#else
	// GCC 2.x version, due to GCC being broken.
	template <typename T> 
	struct is_class : public false_type{};
#endif



	///////////////////////////////////////////////////////////////////////
	// is_enum
	//
	// is_enum<T>::value == true if and only if T is an enumeration type.
	//
	///////////////////////////////////////////////////////////////////////
	struct int_convertible{ int_convertible(int); };

	template <bool is_arithmetic_or_reference>
	struct is_enum_helper { template <typename T> struct nest : public is_convertible<T, int_convertible>{}; };

	template <>
	struct is_enum_helper<true> { template <typename T> struct nest : public false_type {}; };

	template <typename T>
	struct is_enum_helper2
	{
		typedef type_or<is_arithmetic<T>::value, is_reference<T>::value, is_class<T>::value> selector;
		typedef is_enum_helper<selector::value> helper_t;
		typedef typename add_reference<T>::type ref_t;
		typedef typename helper_t::template nest<ref_t> result;
	};

	template <typename T> 
	struct is_enum : public integral_constant<bool, is_enum_helper2<T>::result::value>{};

	template <> struct is_enum<void> : public false_type {};
	template <> struct is_enum<void const> : public false_type {};
	template <> struct is_enum<void volatile> : public false_type {};
	template <> struct is_enum<void const volatile> : public false_type {};

#define EASTL_DECLARE_ENUM(T) namespace mimp{ template <> struct is_enum<T> : public true_type{}; template <> struct is_enum<const T> : public true_type{}; }


	///////////////////////////////////////////////////////////////////////
	// is_polymorphic
	// 
	// is_polymorphic<T>::value == true if and only if T is a class or struct 
	// that declares or inherits a virtual function. is_polymorphic may only 
	// be applied to complete types.
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T>
	struct is_polymorphic_imp1
	{
		typedef typename remove_cv<T>::type t;

		struct helper_1 : public t
		{
			helper_1();
			~helper_1() throw();
			char pad[64];
		};

		struct helper_2 : public t
		{
			helper_2();
			virtual ~helper_2() throw();
#ifndef _MSC_VER
			virtual void foo();
#endif
			char pad[64];
		};

		static const bool value = (sizeof(helper_1) == sizeof(helper_2));
	};

	template <typename T>
	struct is_polymorphic_imp2{ static const bool value = false; };

	template <bool is_class>
	struct is_polymorphic_selector{ template <typename T> struct rebind{ typedef is_polymorphic_imp2<T> type; }; };

	template <>
	struct is_polymorphic_selector<true>{ template <typename T> struct rebind{ typedef is_polymorphic_imp1<T> type; }; };

	template <typename T>
	struct is_polymorphic_value{
		typedef is_polymorphic_selector<is_class<T>::value> selector;
		typedef typename selector::template rebind<T> binder;
		typedef typename binder::type imp_type;
		static const bool value = imp_type::value;
	};

	template <typename T> 
	struct is_polymorphic : public integral_constant<bool, is_polymorphic_value<T>::value>{};




	///////////////////////////////////////////////////////////////////////
	// is_function
	//
	// is_function<T>::value == true  if and only if T is a function type.
	//
	///////////////////////////////////////////////////////////////////////
	template <typename R> struct is_function_ptr_helper : public false_type{};
	template <typename R> struct is_function_ptr_helper<R (*)()> : public true_type{};
	template <typename R, typename Arg0> struct is_function_ptr_helper<R (*)(Arg0)> : public true_type{};
	template <typename R, typename Arg0, typename Arg1> struct is_function_ptr_helper<R (*)(Arg0, Arg1)> : public true_type{};
	template <typename R, typename Arg0, typename Arg1, typename Arg2> struct is_function_ptr_helper<R (*)(Arg0, Arg1, Arg2)> : public true_type{};
	template <typename R, typename Arg0, typename Arg1, typename Arg2, typename Arg3> struct is_function_ptr_helper<R (*)(Arg0, Arg1, Arg2, Arg3)> : public true_type{};
	template <typename R, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4> struct is_function_ptr_helper<R (*)(Arg0, Arg1, Arg2, Arg3, Arg4)> : public true_type{};
	template <typename R, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> struct is_function_ptr_helper<R (*)(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)> : public true_type{};
	template <typename R, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6> struct is_function_ptr_helper<R (*)(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)> : public true_type{};
	template <typename R, typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename Arg7> struct is_function_ptr_helper<R (*)(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)> : public true_type{};

	template <bool is_ref = true>
	struct is_function_chooser{ template <typename T> struct result_ : public false_type{}; };

	template <>
	struct is_function_chooser<false>{ template <typename T> struct result_ : public is_function_ptr_helper<T*>{}; };

	template <typename T>
	struct is_function_value : public is_function_chooser<is_reference<T>::value>::template result_<T>{};

	template <typename T> 
	struct is_function : public integral_constant<bool, is_function_value<T>::value>{};




	///////////////////////////////////////////////////////////////////////
	// is_object
	//
	// is_object<T>::value == true if and only if:
	//    is_reference<T>::value == false, and
	//    is_function<T>::value == false, and
	//    is_void<T>::value == false
	//
	// The C++ standard, section 3.9p9, states: "An object type is a
	// (possibly cv-qualified) type that is not a function type, not a 
	// reference type, and not incomplete (except for an incompletely
	// defined object type).
	///////////////////////////////////////////////////////////////////////

	template <typename T> 
	struct is_object : public integral_constant<bool,
		!is_reference<T>::value && !is_void<T>::value && !is_function<T>::value
	>{};



	///////////////////////////////////////////////////////////////////////
	// is_scalar
	//
	// is_scalar<T>::value == true if and only if:
	//    is_arithmetic<T>::value == true, or
	//    is_enum<T>::value == true, or
	//    is_pointer<T>::value == true, or
	//    is_member_pointer<T>::value
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T>
	struct is_scalar : public integral_constant<bool, is_arithmetic<T>::value || is_enum<T>::value>{};

	template <typename T> struct is_scalar<T*> : public true_type {};
	template <typename T> struct is_scalar<T* const> : public true_type {};
	template <typename T> struct is_scalar<T* volatile> : public true_type {};
	template <typename T> struct is_scalar<T* const volatile> : public true_type {};



	///////////////////////////////////////////////////////////////////////
	// is_compound
	//
	// Compound means anything but fundamental. See C++ standard, section 3.9.2.
	//
	// is_compound<T>::value == true if and only if:
	//    is_fundamental<T>::value == false
	//
	// Thus, is_compound<T>::value == true if and only if:
	//    is_floating_point<T>::value == false, and
	//    is_integral<T>::value == false, and
	//    is_void<T>::value == false
	//
	///////////////////////////////////////////////////////////////////////
	template <typename T> 
	struct is_compound : public integral_constant<bool, !is_fundamental<T>::value>{};



	// The following properties or relations are defined here. If the given 
	// item is missing then it simply hasn't been implemented, at least not yet.
	//    is_empty
	//    is_pod
	//    has_trivial_constructor
	//    has_trivial_copy
	//    has_trivial_assign
	//    has_trivial_destructor
	//    has_trivial_relocate       -- EA extension to the C++ standard proposal.
	//    has_nothrow_constructor
	//    has_nothrow_copy
	//    has_nothrow_assign
	//    has_virtual_destructor




	///////////////////////////////////////////////////////////////////////
	// is_empty
	// 
	// is_empty<T>::value == true if and only if T is an empty class or struct. 
	// is_empty may only be applied to complete types.
	//
	// is_empty cannot be used with union types until is_union can be made to work.
	///////////////////////////////////////////////////////////////////////
	template <typename T>
	struct is_empty_helper_t1 : public T { char m[64]; };
	struct is_empty_helper_t2            { char m[64]; };

	// The inheritance in empty_helper_t1 will not work with non-class types
	template <typename T, bool is_a_class = false>
	struct is_empty_helper : public false_type{};

	template <typename T>
	struct is_empty_helper<T, true> : public integral_constant<bool,
		sizeof(is_empty_helper_t1<T>) == sizeof(is_empty_helper_t2)
	>{};

	template <typename T>
	struct is_empty_helper2
	{
		typedef typename remove_cv<T>::type _T;
		typedef is_empty_helper<_T, is_class<_T>::value> type;
	};

	template <typename T> 
	struct is_empty : public is_empty_helper2<T>::type {};


	///////////////////////////////////////////////////////////////////////
	// is_pod
	// 
	// is_pod<T>::value == true if and only if, for a given type T:
	//    - is_scalar<T>::value == true, or
	//    - T is a class or struct that has no user-defined copy 
	//      assignment operator or destructor, and T has no non-static 
	//      data members M for which is_pod<M>::value == false, and no 
	//      members of reference type, or
	//    - T is a class or struct that has no user-defined copy assignment 
	//      operator or destructor, and T has no non-static data members M for 
	//      which is_pod<M>::value == false, and no members of reference type, or
	//    - T is the type of an array of objects E for which is_pod<E>::value == true
	//
	// is_pod may only be applied to complete types.
	//
	// Without some help from the compiler or user, is_pod will not report 
	// that a struct or class is a POD, but will correctly report that 
	// built-in types such as int are PODs. The user can help the compiler
	// by using the EASTL_DECLARE_POD macro on a class.
	///////////////////////////////////////////////////////////////////////
	template <typename T> // There's not much we can do here without some compiler extension.
	struct is_pod : public integral_constant<bool, is_void<T>::value || is_scalar<T>::value>{};

	template <typename T, size_t N>
	struct is_pod<T[N]> : public is_pod<T>{};

	template <typename T>
	struct is_POD : public is_pod<T>{};

#define EASTL_DECLARE_POD(T) namespace mimp{ template <> struct is_pod<T> : public true_type{}; template <> struct is_pod<const T> : public true_type{}; }




	///////////////////////////////////////////////////////////////////////
	// has_trivial_constructor
	//
	// has_trivial_constructor<T>::value == true if and only if T is a class 
	// or struct that has a trivial constructor. A constructor is trivial if
	//    - it is implicitly defined by the compiler, and
	//    - is_polymorphic<T>::value == false, and
	//    - T has no virtual base classes, and
	//    - for every direct base class of T, has_trivial_constructor<B>::value == true, 
	//      where B is the type of the base class, and
	//    - for every nonstatic data member of T that has class type or array 
	//      of class type, has_trivial_constructor<M>::value == true, 
	//      where M is the type of the data member
	//
	// has_trivial_constructor may only be applied to complete types.
	//
	// Without from the compiler or user, has_trivial_constructor will not 
	// report that a class or struct has a trivial constructor. 
	// The user can use EASTL_DECLARE_TRIVIAL_CONSTRUCTOR to help the compiler.
	//
	// A default constructor for a class X is a constructor of class X that 
	// can be called without an argument.
	///////////////////////////////////////////////////////////////////////

	// With current compilers, this is all we can do.
	template <typename T> 
	struct has_trivial_constructor : public is_pod<T> {};

#define EASTL_DECLARE_TRIVIAL_CONSTRUCTOR(T) namespace mimp{ template <> struct has_trivial_constructor<T> : public true_type{}; template <> struct has_trivial_constructor<const T> : public true_type{}; }




	///////////////////////////////////////////////////////////////////////
	// has_trivial_copy
	//
	// has_trivial_copy<T>::value == true if and only if T is a class or 
	// struct that has a trivial copy constructor. A copy constructor is 
	// trivial if
	//   - it is implicitly defined by the compiler, and
	//   - is_polymorphic<T>::value == false, and
	//   - T has no virtual base classes, and
	//   - for every direct base class of T, has_trivial_copy<B>::value == true, 
	//     where B is the type of the base class, and
	//   - for every nonstatic data member of T that has class type or array 
	//     of class type, has_trivial_copy<M>::value == true, where M is the 
	//     type of the data member
	//
	// has_trivial_copy may only be applied to complete types.
	//
	// Another way of looking at this is:
	// A copy constructor for class X is trivial if it is implicitly 
	// declared and if all the following are true:
	//    - Class X has no virtual functions (10.3) and no virtual base classes (10.1).
	//    - Each direct base class of X has a trivial copy constructor.
	//    - For all the nonstatic data members of X that are of class type 
	//      (or array thereof), each such class type has a trivial copy constructor;
	//      otherwise the copy constructor is nontrivial.
	//
	// Without from the compiler or user, has_trivial_copy will not report 
	// that a class or struct has a trivial copy constructor. The user can 
	// use EASTL_DECLARE_TRIVIAL_COPY to help the compiler.
	///////////////////////////////////////////////////////////////////////

	template <typename T> 
	struct has_trivial_copy : public integral_constant<bool, is_pod<T>::value && !is_volatile<T>::value>{};

#define EASTL_DECLARE_TRIVIAL_COPY(T) namespace mimp{ template <> struct has_trivial_copy<T> : public true_type{}; template <> struct has_trivial_copy<const T> : public true_type{}; }


	///////////////////////////////////////////////////////////////////////
	// has_trivial_assign
	//
	// has_trivial_assign<T>::value == true if and only if T is a class or 
	// struct that has a trivial copy assignment operator. A copy assignment 
	// operator is trivial if:
	//    - it is implicitly defined by the compiler, and
	//    - is_polymorphic<T>::value == false, and
	//    - T has no virtual base classes, and
	//    - for every direct base class of T, has_trivial_assign<B>::value == true, 
	//      where B is the type of the base class, and
	//    - for every nonstatic data member of T that has class type or array 
	//      of class type, has_trivial_assign<M>::value == true, where M is 
	//      the type of the data member.
	//
	// has_trivial_assign may only be applied to complete types.
	//
	// Without  from the compiler or user, has_trivial_assign will not 
	// report that a class or struct has trivial assignment. The user 
	// can use EASTL_DECLARE_TRIVIAL_ASSIGN to help the compiler.
	///////////////////////////////////////////////////////////////////////

	template <typename T> 
	struct has_trivial_assign : public integral_constant<bool,
		is_pod<T>::value && !is_const<T>::value && !is_volatile<T>::value
	>{};

#define EASTL_DECLARE_TRIVIAL_ASSIGN(T) namespace mimp{ template <> struct has_trivial_assign<T> : public true_type{}; template <> struct has_trivial_assign<const T> : public true_type{}; }




	///////////////////////////////////////////////////////////////////////
	// has_trivial_destructor
	//
	// has_trivial_destructor<T>::value == true if and only if T is a class 
	// or struct that has a trivial destructor. A destructor is trivial if
	//    - it is implicitly defined by the compiler, and
	//    - for every direct base class of T, has_trivial_destructor<B>::value == true, 
	//      where B is the type of the base class, and
	//    - for every nonstatic data member of T that has class type or 
	//      array of class type, has_trivial_destructor<M>::value == true, 
	//      where M is the type of the data member
	//
	// has_trivial_destructor may only be applied to complete types.
	//
	// Without from the compiler or user, has_trivial_destructor will not 
	// report that a class or struct has a trivial destructor. 
	// The user can use EASTL_DECLARE_TRIVIAL_DESTRUCTOR to help the compiler.
	///////////////////////////////////////////////////////////////////////

	// With current compilers, this is all we can do.
	template <typename T> 
	struct has_trivial_destructor : public is_pod<T>{};

#define EASTL_DECLARE_TRIVIAL_DESTRUCTOR(T) namespace mimp{ template <> struct has_trivial_destructor<T> : public true_type{}; template <> struct has_trivial_destructor<const T> : public true_type{}; }


	///////////////////////////////////////////////////////////////////////
	// has_trivial_relocate
	//
	// This is an EA extension to the type traits standard.
	//
	// A trivially relocatable object is one that can be safely memmove'd 
	// to uninitialized memory. construction, assignment, and destruction 
	// properties are not addressed by this trait. A type that has the 
	// is_fundamental trait would always have the has_trivial_relocate trait. 
	// A type that has the has_trivial_constructor, has_trivial_copy or 
	// has_trivial_assign traits would usally have the has_trivial_relocate 
	// trait, but this is not strictly guaranteed.
	//
	// The user can use EASTL_DECLARE_TRIVIAL_RELOCATE to help the compiler.
	///////////////////////////////////////////////////////////////////////

	// With current compilers, this is all we can do.
	template <typename T> 
	struct has_trivial_relocate : public integral_constant<bool, is_pod<T>::value && !is_volatile<T>::value>{};

#define EASTL_DECLARE_TRIVIAL_RELOCATE(T) namespace mimp{ template <> struct has_trivial_relocate<T> : public true_type{}; template <> struct has_trivial_relocate<const T> : public true_type{}; }


///////////////////////////////////////////////////////////////////////////////
// EASTL/allocator.h
//
// Written and maintained by Paul Pedriana.
///////////////////////////////////////////////////////////////////////////////

	/// EASTL_ALLOCATOR_DEFAULT_NAME
	///
	/// Defines a default allocator name in the absence of a user-provided name.
	///
#ifndef EASTL_ALLOCATOR_DEFAULT_NAME
#define EASTL_ALLOCATOR_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX // Unless the user overrides something, this is "EASTL".
#endif


	/// alloc_flags
	///
	/// Defines allocation flags.
	///
	enum alloc_flags 
	{
		MEM_TEMP = 0, // Low memory, not necessarily actually temporary.
		MEM_PERM = 1  // High memory, for things that won't be unloaded.
	};


	/// allocator
	///
	/// In this allocator class, note that it is not templated on any type and
	/// instead it simply allocates blocks of memory much like the C malloc and
	/// free functions. It can be thought of as similar to C++ std::allocator<char>.
	/// The flags parameter has meaning that is specific to the allocation 
	///
	class  allocator
	{
	public:
		EASTL_ALLOCATOR_EXPLICIT allocator(const char* pName = EASTL_NAME_VAL(EASTL_ALLOCATOR_DEFAULT_NAME));
		allocator(const allocator& x);
		allocator(const allocator& x, const char* pName);

		allocator& operator=(const allocator& x);

		void* allocate(size_t n, int flags = 0);
		void* allocate(size_t n, size_t alignment, size_t offset, int flags = 0);
		void  deallocate(void* p, size_t n);

		const char* get_name() const;
		void        set_name(const char* pName);

	protected:
#if EASTL_NAME_ENABLED
		const char* mpName; // Debug name, used to track memory.
#endif
	};

	bool operator==(const allocator& a, const allocator& b);
	bool operator!=(const allocator& a, const allocator& b);

	 allocator* GetDefaultAllocator();
	 allocator* SetDefaultAllocator(allocator* pAllocator);



	/// get_default_allocator
	///
	/// This templated function allows the user to implement a default allocator
	/// retrieval function that any part of EASTL can use. EASTL containers take
	/// an Allocator parameter which identifies an Allocator class to use. But 
	/// different kinds of allocators have different mechanisms for retrieving 
	/// a default allocator instance, and some don't even intrinsically support
	/// such functionality. The user can override this get_default_allocator 
	/// function in order to provide the glue between EASTL and whatever their
	/// system's default allocator happens to be.
	///
	/// Example usage:
	///     MyAllocatorType* gpSystemAllocator;
	///     
	///     MyAllocatorType* get_default_allocator(const MyAllocatorType*)
	///         { return gpSystemAllocator; }
	///
	template <typename Allocator>
	inline Allocator* get_default_allocator(const Allocator*)
	{
		return NULL; // By default we return NULL; the user must make specialization of this function in order to provide their own implementation.
	}

	inline EASTLAllocatorType* get_default_allocator(const EASTLAllocatorType*)
	{
		return EASTLAllocatorDefault(); // For the built-in allocator EASTLAllocatorType, we happen to already have a function for returning the default allocator instance, so we provide it.
	}


	/// default_allocfreemethod
	///
	/// Implements a default allocfreemethod which uses the default global allocator.
	/// This version supports only default alignment.
	///
	inline void* default_allocfreemethod(size_t n, void* pBuffer, void* /*pContext*/)
	{
		EASTLAllocatorType* const pAllocator = EASTLAllocatorDefault();

		if(pBuffer) // If freeing...
		{
			EASTLFree(*pAllocator, pBuffer, n);
			return NULL;  // The return value is meaningless for the free.
		}
		else // allocating
			return EASTLAlloc(*pAllocator, n);
	}


	/// allocate_memory
	///
	/// This is a memory allocation dispatching function.
	/// To do: Make aligned and unaligned specializations.
	///        Note that to do this we will need to use a class with a static
	///        function instead of a standalone function like below.
	///
	template <typename Allocator>
	void* allocate_memory(Allocator& a, size_t n, size_t alignment, size_t alignmentOffset)
	{
		if(alignment <= 8)
			return EASTLAlloc(a, n);
		return EASTLAllocAligned(a, n, alignment, alignmentOffset);
	}


#ifndef EASTL_USER_DEFINED_ALLOCATOR // If the user hasn't declared that he has defined a different allocator implementation elsewhere...

	inline allocator::allocator(const char* EASTL_NAME(pName))
	{
#if EASTL_NAME_ENABLED
		mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME;
#endif
	}


	inline allocator::allocator(const allocator& EASTL_NAME(alloc))
	{
#if EASTL_NAME_ENABLED
		mpName = alloc.mpName;
#endif
	}


	inline allocator::allocator(const allocator&, const char* EASTL_NAME(pName))
	{
#if EASTL_NAME_ENABLED
		mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME;
#endif
	}


	inline allocator& allocator::operator=(const allocator& EASTL_NAME(alloc))
	{
#if EASTL_NAME_ENABLED
		mpName = alloc.mpName;
#endif
		return *this;
	}


	inline const char* allocator::get_name() const
	{
#if EASTL_NAME_ENABLED
		return mpName;
#else
		return EASTL_ALLOCATOR_DEFAULT_NAME;
#endif
	}


	inline void allocator::set_name(const char* EASTL_NAME(pName))
	{
#if EASTL_NAME_ENABLED
		mpName = pName;
#endif
	}


	inline void* allocator::allocate(size_t n, int /*flags*/)
	{
#if EASTL_NAME_ENABLED
		return MI_ALLOC(n);
#else
		return MI_ALLOC(n);
#endif
	}


	inline void* allocator::allocate(size_t n, size_t /*alignment*/, size_t /*offset*/, int /*flags*/)
	{
#if EASTL_NAME_ENABLED
		return MI_ALLOC(n);
#else
		return MI_ALLOC(n);
#endif
	}


	inline void allocator::deallocate(void* p, size_t)
	{
		MI_FREE(p);
	}


	inline bool operator==(const allocator&, const allocator&)
	{
		return true; // All allocators are considered equal, as they merely use global new/delete.
	}


	inline bool operator!=(const allocator&, const allocator&)
	{
		return false; // All allocators are considered equal, as they merely use global new/delete.
	}



#endif

///////////////////////////////////////////////////////////////////////////////
// EASTL/iterator.h
//
// Written and maintained by Paul Pedriana.
///////////////////////////////////////////////////////////////////////////////



	/// iterator_status_flag
	/// 
	/// Defines the validity status of an iterator. This is primarily used for 
	/// iterator validation in debug builds. These are implemented as OR-able 
	/// flags (as opposed to mutually exclusive values) in order to deal with 
	/// the nature of iterator status. In particular, an iterator may be valid
	/// but not dereferencable, as in the case with an iterator to container end().
	/// An iterator may be valid but also dereferencable, as in the case with an
	/// iterator to container begin().
	///
	enum iterator_status_flag
	{
		isf_none            = 0x00, /// This is called none and not called invalid because it is not strictly the opposite of invalid.
		isf_valid           = 0x01, /// The iterator is valid, which means it is in the range of [begin, end].
		isf_current         = 0x02, /// The iterator is valid and points to the same element it did when created. For example, if an iterator points to vector::begin() but an element is inserted at the front, the iterator is valid but not current. Modification of elements in place do not make iterators non-current.
		isf_can_dereference = 0x04  /// The iterator is dereferencable, which means it is in the range of [begin, end). It may or may not be current.
	};



	// The following declarations are taken directly from the C++ standard document.
	//    input_iterator_tag, etc.
	//    iterator
	//    iterator_traits
	//    reverse_iterator

	// Iterator categories
	// Every iterator is defined as belonging to one of the iterator categories that
	// we define here. These categories come directly from the C++ standard.
	struct input_iterator_tag { };
	struct output_iterator_tag { };
	struct forward_iterator_tag       : public input_iterator_tag { };
	struct bidirectional_iterator_tag : public forward_iterator_tag { };
	struct random_access_iterator_tag : public bidirectional_iterator_tag { };
	struct contiguous_iterator_tag    : public random_access_iterator_tag { };  // Extension to the C++ standard. Contiguous ranges are more than random access, they are physically contiguous.

	// struct iterator
	template <typename Category, typename T, typename Distance = ptrdiff_t, 
		typename Pointer = T*, typename Reference = T&>
	struct iterator
	{
		typedef Category  iterator_category;
		typedef T         value_type;
		typedef Distance  difference_type;
		typedef Pointer   pointer;
		typedef Reference reference;
	};


	// struct iterator_traits
	template <typename Iterator>
	struct iterator_traits
	{
		typedef typename Iterator::iterator_category iterator_category;
		typedef typename Iterator::value_type        value_type;
		typedef typename Iterator::difference_type   difference_type;
		typedef typename Iterator::pointer           pointer;
		typedef typename Iterator::reference         reference;
	};

	template <typename T>
	struct iterator_traits<T*>
	{
		typedef EASTL_ITC_NS::random_access_iterator_tag iterator_category;     // To consider: Change this to contiguous_iterator_tag for the case that 
		typedef T                                        value_type;            //              EASTL_ITC_NS is "mimp" instead of "std".
		typedef ptrdiff_t                                difference_type;
		typedef T*                                       pointer;
		typedef T&                                       reference;
	};

	template <typename T>
	struct iterator_traits<const T*>
	{
		typedef EASTL_ITC_NS::random_access_iterator_tag iterator_category;
		typedef T                                        value_type;
		typedef ptrdiff_t                                difference_type;
		typedef const T*                                 pointer;
		typedef const T&                                 reference;
	};





	/// reverse_iterator
	///
	/// From the C++ standard:
	/// Bidirectional and random access iterators have corresponding reverse 
	/// iterator adaptors that iterate through the data structure in the 
	/// opposite direction. They have the same signatures as the corresponding 
	/// iterators. The fundamental relation between a reverse iterator and its 
	/// corresponding iterator i is established by the identity:
	///     &*(reverse_iterator(i)) == &*(i - 1).
	/// This mapping is dictated by the fact that while there is always a pointer 
	/// past the end of an array, there might not be a valid pointer before the
	/// beginning of an array.
	///
	template <typename Iterator>
	class reverse_iterator : public iterator<typename mimp::iterator_traits<Iterator>::iterator_category,
		typename mimp::iterator_traits<Iterator>::value_type,
		typename mimp::iterator_traits<Iterator>::difference_type,
		typename mimp::iterator_traits<Iterator>::pointer,
		typename mimp::iterator_traits<Iterator>::reference>
	{
	public:
		typedef Iterator                                                   iterator_type;
		typedef typename mimp::iterator_traits<Iterator>::pointer         pointer;
		typedef typename mimp::iterator_traits<Iterator>::reference       reference;
		typedef typename mimp::iterator_traits<Iterator>::difference_type difference_type;

	protected:
		Iterator mIterator;

	public:
		reverse_iterator()      // It's important that we construct mIterator, because if Iterator  
			: mIterator() { }   // is a pointer, there's a difference between doing it and not.

		explicit reverse_iterator(iterator_type i)
			: mIterator(i) { }

		reverse_iterator(const reverse_iterator& ri)
			: mIterator(ri.mIterator) { }

		template <typename U>
		reverse_iterator(const reverse_iterator<U>& ri)
			: mIterator(ri.base()) { }

		// This operator= isn't in the standard, but the the C++ 
		// library working group has tentatively approved it, as it
		// allows const and non-const reverse_iterators to interoperate.
		template <typename U>
		reverse_iterator<Iterator>& operator=(const reverse_iterator<U>& ri)
		{ mIterator = ri.base(); return *this; }

		iterator_type base() const
		{ return mIterator; }

		reference operator*() const
		{
			iterator_type i(mIterator);
			return *--i;
		}

		pointer operator->() const
		{ return &(operator*()); }

		reverse_iterator& operator++()
		{ --mIterator; return *this; }

		reverse_iterator operator++(int)
		{
			reverse_iterator ri(*this);
			--mIterator;
			return ri;
		}

		reverse_iterator& operator--()
		{ ++mIterator; return *this; }

		reverse_iterator operator--(int)
		{
			reverse_iterator ri(*this);
			++mIterator;
			return ri;
		}

		reverse_iterator operator+(difference_type n) const
		{ return reverse_iterator(mIterator - n); }

		reverse_iterator& operator+=(difference_type n)
		{ mIterator -= n; return *this; }

		reverse_iterator operator-(difference_type n) const
		{ return reverse_iterator(mIterator + n); }

		reverse_iterator& operator-=(difference_type n)
		{ mIterator += n; return *this; }

		reference operator[](difference_type n) const
		{ return mIterator[-n - 1]; } 
	};


	// The C++ library working group has tentatively approved the usage of two
	// template parameters (Iterator1 and Iterator2) in order to allow reverse_iterators
	// and const_reverse iterators to be comparable. This is a similar issue to the 
	// C++ defect report #179 regarding comparison of container iterators and const_iterators.
	template <typename Iterator1, typename Iterator2>
	inline bool
		operator==(const reverse_iterator<Iterator1>& a, const reverse_iterator<Iterator2>& b)
	{ return a.base() == b.base(); }


	template <typename Iterator1, typename Iterator2>
	inline bool
		operator<(const reverse_iterator<Iterator1>& a, const reverse_iterator<Iterator2>& b)
	{ return a.base() > b.base(); }


	template <typename Iterator1, typename Iterator2>
	inline bool
		operator!=(const reverse_iterator<Iterator1>& a, const reverse_iterator<Iterator2>& b)
	{ return a.base() != b.base(); }


	template <typename Iterator1, typename Iterator2>
	inline bool
		operator>(const reverse_iterator<Iterator1>& a, const reverse_iterator<Iterator2>& b)
	{ return a.base() < b.base(); }


	template <typename Iterator1, typename Iterator2>
	inline bool
		operator<=(const reverse_iterator<Iterator1>& a, const reverse_iterator<Iterator2>& b)
	{ return a.base() >= b.base(); }


	template <typename Iterator1, typename Iterator2>
	inline bool
		operator>=(const reverse_iterator<Iterator1>& a, const reverse_iterator<Iterator2>& b)
	{ return a.base() <= b.base(); }


	template <typename Iterator1, typename Iterator2>
	inline typename reverse_iterator<Iterator1>::difference_type
		operator-(const reverse_iterator<Iterator1>& a, const reverse_iterator<Iterator2>& b)
	{ return b.base() - a.base(); }


	template <typename Iterator>
	inline reverse_iterator<Iterator>
		operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& a)
	{ return reverse_iterator<Iterator>(a.base() - n); }







	/// back_insert_iterator
	///
	/// A back_insert_iterator is simply a class that acts like an iterator but when you 
	/// assign a value to it, it calls push_back on the container with the value.
	///
	template <typename Container>
	class back_insert_iterator : public iterator<EASTL_ITC_NS::output_iterator_tag, void, void, void, void>
	{
	public:
		typedef Container                           container_type;
		typedef typename Container::const_reference const_reference;

	protected:
		Container& container;

	public:
		explicit back_insert_iterator(Container& x)
			: container(x) { }

		back_insert_iterator& operator=(const_reference value)
		{ container.push_back(value); return *this; }

		back_insert_iterator& operator*()
		{ return *this; }

		back_insert_iterator& operator++()
		{ return *this; } // This is by design.

		back_insert_iterator operator++(int)
		{ return *this; } // This is by design.
	};


	/// back_inserter
	///
	/// Creates an instance of a back_insert_iterator.
	///
	template <typename Container>
	inline back_insert_iterator<Container>
		back_inserter(Container& x)
	{ return back_insert_iterator<Container>(x); }




	/// front_insert_iterator
	///
	/// A front_insert_iterator is simply a class that acts like an iterator but when you 
	/// assign a value to it, it calls push_front on the container with the value.
	///
	template <typename Container>
	class front_insert_iterator : public iterator<EASTL_ITC_NS::output_iterator_tag, void, void, void, void>
	{
	public:
		typedef Container                           container_type;
		typedef typename Container::const_reference const_reference;

	protected:
		Container& container;

	public:
		explicit front_insert_iterator(Container& x)
			: container(x) { }

		front_insert_iterator& operator=(const_reference value)
		{ container.push_front(value); return *this; }

		front_insert_iterator& operator*()
		{ return *this; }

		front_insert_iterator& operator++()
		{ return *this; } // This is by design.

		front_insert_iterator operator++(int)
		{ return *this; } // This is by design.
	};


	/// front_inserter
	///
	/// Creates an instance of a front_insert_iterator.
	///
	template <typename Container>
	inline front_insert_iterator<Container>
		front_inserter(Container& x)
	{ return front_insert_iterator<Container>(x); }




	/// insert_iterator
	///
	/// An insert_iterator is like an iterator except that when you assign a value to it, 
	/// the insert_iterator inserts the value into the container and increments the iterator.
	///
	/// insert_iterator is an iterator adaptor that functions as an OutputIterator: 
	/// assignment through an insert_iterator inserts an object into a container. 
	/// Specifically, if ii is an insert_iterator, then ii keeps track of a container c and 
	/// an insertion point p; the expression *ii = x performs the insertion c.insert(p, x).
	///
	/// If you assign through an insert_iterator several times, then you will be inserting 
	/// several elements into the underlying container. In the case of a sequence, they will 
	/// appear at a particular location in the underlying sequence, in the order in which 
	/// they were inserted: one of the arguments to insert_iterator's constructor is an 
	/// iterator p, and the new range will be inserted immediately before p.
	///
	template <typename Container>
	class insert_iterator : public iterator<EASTL_ITC_NS::output_iterator_tag, void, void, void, void>
	{
	public:
		typedef Container                           container_type;
		typedef typename Container::iterator        iterator_type;
		typedef typename Container::const_reference const_reference;

	protected:
		Container&     container;
		iterator_type  it; 

	public:
		// This assignment operator is defined more to stop compiler warnings (e.g. VC++ C4512)
		// than to be useful. However, it does an insert_iterator to be assigned to another 
		// insert iterator provided that they point to the same container.
		insert_iterator& operator=(const insert_iterator& x)
		{
			EASTL_ASSERT(&x.container == &container);
			it = x.it;
			return *this;
		}

		insert_iterator(Container& x, iterator_type itNew)
			: container(x), it(itNew) {}

		insert_iterator& operator=(const_reference value)
		{
			it = container.insert(it, value);
			++it;
			return *this;
		}

		insert_iterator& operator*()
		{ return *this; }

		insert_iterator& operator++()
		{ return *this; } // This is by design.

		insert_iterator& operator++(int)
		{ return *this; } // This is by design.

	}; // insert_iterator 


	/// inserter
	///
	/// Creates an instance of an insert_iterator.
	///
	template <typename Container, typename Iterator>
	inline mimp::insert_iterator<Container>
		inserter(Container& x, Iterator i)
	{
		typedef typename Container::iterator iterator;
		return mimp::insert_iterator<Container>(x, iterator(i));
	}




	//////////////////////////////////////////////////////////////////////////////////
	/// distance
	///
	/// Implements the distance() function. There are two versions, one for
	/// random access iterators (e.g. with vector) and one for regular input
	/// iterators (e.g. with list). The former is more efficient.
	///
	template <typename InputIterator>
	inline typename mimp::iterator_traits<InputIterator>::difference_type
		distance_impl(InputIterator first, InputIterator last, EASTL_ITC_NS::input_iterator_tag)
	{
		typename mimp::iterator_traits<InputIterator>::difference_type n = 0;

		while(first != last)
		{
			++first;
			++n;
		}
		return n;
	}

	template <typename RandomAccessIterator>
	inline typename mimp::iterator_traits<RandomAccessIterator>::difference_type
		distance_impl(RandomAccessIterator first, RandomAccessIterator last, EASTL_ITC_NS::random_access_iterator_tag)
	{
		return last - first;
	}

	// Special version defined so that std C++ iterators can be recognized by 
	// this function. Unfortunately, this function treats all foreign iterators
	// as InputIterators and thus can seriously hamper performance in the case
	// of large ranges of bidirectional_iterator_tag iterators.
	//template <typename InputIterator>
	//inline typename mimp::iterator_traits<InputIterator>::difference_type
	//distance_impl(InputIterator first, InputIterator last, ...)
	//{
	//    typename mimp::iterator_traits<InputIterator>::difference_type n = 0;
	//
	//    while(first != last)
	//    {
	//        ++first;
	//        ++n;
	//    }
	//    return n;
	//}

	template <typename InputIterator>
	inline typename mimp::iterator_traits<InputIterator>::difference_type
		distance(InputIterator first, InputIterator last)
	{
		typedef typename mimp::iterator_traits<InputIterator>::iterator_category IC;

		return mimp::distance_impl(first, last, IC());
	}




	//////////////////////////////////////////////////////////////////////////////////
	/// advance
	///
	/// Implements the advance() function. There are three versions, one for
	/// random access iterators (e.g. with vector), one for bidirectional 
	/// iterators (list) and one for regular input iterators (e.g. with slist). 
	///
	template <typename InputIterator, typename Distance>
	inline void
		advance_impl(InputIterator& i, Distance n, EASTL_ITC_NS::input_iterator_tag)
	{
		while(n--)
			++i;
	}

	template <typename BidirectionalIterator, typename Distance>
	inline void
		advance_impl(BidirectionalIterator& i, Distance n, EASTL_ITC_NS::bidirectional_iterator_tag)
	{
		if(n > 0)
		{
			while(n--)
				++i;
		}
		else
		{
			while(n++)
				--i;
		}
	}

	template <typename RandomAccessIterator, typename Distance>
	inline void
		advance_impl(RandomAccessIterator& i, Distance n, EASTL_ITC_NS::random_access_iterator_tag)
	{
		i += n;
	}

	// Special version defined so that std C++ iterators can be recognized by 
	// this function. Unfortunately, this function treats all foreign iterators
	// as InputIterators and thus can seriously hamper performance in the case
	// of large ranges of bidirectional_iterator_tag iterators.
	//template <typename InputIterator, typename Distance>
	//inline void
	//advance_impl(InputIterator& i, Distance n, ...)
	//{
	//    while(n--)
	//        ++i;
	//}

	template <typename InputIterator, typename Distance>
	inline void
		advance(InputIterator& i, Distance n)
	{
		typedef typename mimp::iterator_traits<InputIterator>::iterator_category IC;

		mimp::advance_impl(i, n, IC());
	}



///////////////////////////////////////////////////////////////////////////////
// EASTL/utility.h
// Written and maintained by Paul Pedriana - 2005.
///////////////////////////////////////////////////////////////////////////////

	///////////////////////////////////////////////////////////////////////
	/// rel_ops
	///
	/// rel_ops allow the automatic generation of operators !=, >, <=, >= from
	/// just operators == and <. These are intentionally in the rel_ops namespace
	/// so that they don't conflict with other similar operators. To use these 
	/// operators, add "using namespace std::rel_ops;" to an appropriate place in 
	/// your code, usually right in the function that you need them to work.
	/// In fact, you will very likely have collision problems if you put such
	/// using statements anywhere other than in the .cpp file like so and may 
	/// also have collisions when you do, as the using statement will affect all
	/// code in the module. You need to be careful about use of rel_ops.
	///
	namespace rel_ops
	{
		template <typename T>
		inline bool operator!=(const T& x, const T& y)
		{ return !(x == y); }

		template <typename T>
		inline bool operator>(const T& x, const T& y)
		{ return (y < x); }

		template <typename T>
		inline bool operator<=(const T& x, const T& y)
		{ return !(y < x); }

		template <typename T>
		inline bool operator>=(const T& x, const T& y)
		{ return !(x < y); }
	}



	///////////////////////////////////////////////////////////////////////
	/// pair
	///
	/// Implements a simple pair, just like the C++ std::pair.
	///
	template <typename T1, typename T2>
	struct pair
	{
		typedef T1 first_type;
		typedef T2 second_type;

		T1 first;
		T2 second;

		pair();
		pair(const T1& x);
		pair(const T1& x, const T2& y);

		template <typename U, typename V>
		pair(const pair<U, V>& p);

		// pair(const pair& p);              // Not necessary, as default version is OK.
		// pair& operator=(const pair& p);   // Not necessary, as default version is OK.
	};




	/// use_self
	///
	/// operator()(x) simply returns x. Used in sets, as opposed to maps.
	/// This is a template policy implementation; it is an alternative to 
	/// the use_first template implementation.
	///
	/// The existance of use_self may seem odd, given that it does nothing,
	/// but these kinds of things are useful, virtually required, for optimal 
	/// generic programming.
	///
	template <typename T>
	struct use_self             // : public unary_function<T, T> // Perhaps we want to make it a subclass of unary_function.
	{
		typedef T result_type;

		const T& operator()(const T& x) const
		{ return x; }
	};

	/// use_first
	///
	/// operator()(x) simply returns x.first. Used in maps, as opposed to sets.
	/// This is a template policy implementation; it is an alternative to 
	/// the use_self template implementation. This is the same thing as the
	/// SGI SGL select1st utility.
	///
	template <typename Pair>
	struct use_first            // : public unary_function<Pair, typename Pair::first_type> // Perhaps we want to make it a subclass of unary_function.
	{
		typedef typename Pair::first_type result_type;

		const result_type& operator()(const Pair& x) const
		{ return x.first; }
	};

	/// use_second
	///
	/// operator()(x) simply returns x.second. 
	/// This is the same thing as the SGI SGL select2nd utility
	///
	template <typename Pair>
	struct use_second           // : public unary_function<Pair, typename Pair::second_type> // Perhaps we want to make it a subclass of unary_function.
	{
		typedef typename Pair::second_type result_type;

		const result_type& operator()(const Pair& x) const
		{ return x.second; }
	};





	///////////////////////////////////////////////////////////////////////
	// pair
	///////////////////////////////////////////////////////////////////////

	template <typename T1, typename T2>
	inline pair<T1, T2>::pair()
		: first(), second()
	{
		// Empty
	}


	template <typename T1, typename T2>
	inline pair<T1, T2>::pair(const T1& x)
		: first(x), second()
	{
		// Empty
	}


	template <typename T1, typename T2>
	inline pair<T1, T2>::pair(const T1& x, const T2& y)
		: first(x), second(y)
	{
		// Empty
	}


	template <typename T1, typename T2>
	template <typename U, typename V>
	inline pair<T1, T2>::pair(const pair<U, V>& p)
		: first(p.first), second(p.second)
	{
		// Empty
	}




	///////////////////////////////////////////////////////////////////////
	// global operators
	///////////////////////////////////////////////////////////////////////

	template <typename T1, typename T2>
	inline bool operator==(const pair<T1, T2>& a, const pair<T1, T2>& b)
	{
		return ((a.first == b.first) && (a.second == b.second));
	}


	template <typename T1, typename T2>
	inline bool operator<(const pair<T1, T2>& a, const pair<T1, T2>& b)
	{
		// Note that we use only operator < in this expression. Otherwise we could
		// use the simpler: return (a.m1 == b.m1) ? (a.m2 < b.m2) : (a.m1 < b.m1);
		// The user can write a specialization for this operator to get around this
		// in cases where the highest performance is required.
		return ((a.first < b.first) || (!(b.first < a.first) && (a.second < b.second)));
	}


	template <typename T1, typename T2>
	inline bool operator!=(const pair<T1, T2>& a, const pair<T1, T2>& b)
	{
		return !(a == b);
	}


	template <typename T1, typename T2>
	inline bool operator>(const pair<T1, T2>& a, const pair<T1, T2>& b)
	{
		return b < a;
	}


	template <typename T1, typename T2>
	inline bool operator>=(const pair<T1, T2>& a, const pair<T1, T2>& b)
	{
		return !(a < b);
	}


	template <typename T1, typename T2>
	inline bool operator<=(const pair<T1, T2>& a, const pair<T1, T2>& b)
	{
		return !(b < a);
	}




	///////////////////////////////////////////////////////////////////////
	/// make_pair / make_pair_ref
	///
	/// make_pair is the same as std::make_pair specified by the C++ standard.
	/// If you look at the C++ standard, you'll see that it specifies T& instead of T.
	/// However, it has been determined that the C++ standard is incorrect and has 
	/// flagged it as a defect (http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#181).
	/// In case you feel that you want a more efficient version that uses references,
	/// we provide the make_pair_ref function below.
	/// 
	/// Note: You don't need to use make_pair in order to make a pair. The following
	/// code is equivalent, and the latter avoids one more level of inlining:
	///     return make_pair(charPtr, charPtr);
	///     return pair<char*, char*>(charPtr, charPtr);
	///
	template <typename T1, typename T2>
	inline pair<T1, T2> make_pair(T1 a, T2 b)
	{
		return pair<T1, T2>(a, b);
	}


	template <typename T1, typename T2>
	inline pair<T1, T2> make_pair_ref(const T1& a, const T2& b)
	{
		return pair<T1, T2>(a, b);
	}



	/// swap
	///
	/// Assigns the contents of a to b and the contents of b to a. 
	/// A temporary instance of type T is created and destroyed
	/// in the process.
	///
	/// This function is used by numerous other algorithms, and as 
	/// such it may in some cases be feasible and useful for the user 
	/// to implement an override version of this function which is 
	/// more efficient in some way. 
	///
	template <typename T>
	inline void swap(T& a, T& b)
	{
		T temp(a);
		a = b;
		b = temp;
	}



	// iter_swap helper functions
	//
	template <bool bTypesAreEqual>
	struct iter_swap_impl
	{
		template <typename ForwardIterator1, typename ForwardIterator2>
		static void iter_swap(ForwardIterator1 a, ForwardIterator2 b)
		{
			typedef typename mimp::iterator_traits<ForwardIterator1>::value_type value_type_a;

			value_type_a temp(*a);
			*a = *b;
			*b = temp; 
		}
	};

	template <>
	struct iter_swap_impl<true>
	{
		template <typename ForwardIterator1, typename ForwardIterator2>
		static void iter_swap(ForwardIterator1 a, ForwardIterator2 b)
		{
			mimp::swap(*a, *b);
		}
	};

	/// iter_swap
	///
	/// Equivalent to swap(*a, *b), though the user can provide an override to
	/// iter_swap that is independent of an override which may exist for swap.
	///
	/// We provide a version of iter_swap which uses swap when the swapped types 
	/// are equal but a manual implementation otherwise. We do this because the 
	/// C++ standard defect report says that iter_swap(a, b) must be implemented 
	/// as swap(*a, *b) when possible.
	///
	template <typename ForwardIterator1, typename ForwardIterator2>
	inline void iter_swap(ForwardIterator1 a, ForwardIterator2 b)
	{
		typedef typename mimp::iterator_traits<ForwardIterator1>::value_type value_type_a;
		typedef typename mimp::iterator_traits<ForwardIterator2>::value_type value_type_b;
		typedef typename mimp::iterator_traits<ForwardIterator1>::reference  reference_a;
		typedef typename mimp::iterator_traits<ForwardIterator2>::reference  reference_b;

		iter_swap_impl<type_and<is_same<value_type_a, value_type_b>::value, is_same<value_type_a&, reference_a>::value, is_same<value_type_b&, reference_b>::value >::value >::iter_swap(a, b);
	}




	/// EASTL_RBTREE_DEFAULT_NAME
	///
	/// Defines a default container name in the absence of a user-provided name.
	///
#ifndef EASTL_RBTREE_DEFAULT_NAME
#define EASTL_RBTREE_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " rbtree" // Unless the user overrides something, this is "EASTL rbtree".
#endif


	/// EASTL_RBTREE_DEFAULT_ALLOCATOR
	///
#ifndef EASTL_RBTREE_DEFAULT_ALLOCATOR
#define EASTL_RBTREE_DEFAULT_ALLOCATOR allocator_type(EASTL_RBTREE_DEFAULT_NAME)
#endif



	/// RBTreeColor
	///
	enum RBTreeColor
	{
		kRBTreeColorRed,
		kRBTreeColorBlack
	};



	/// RBTreeColor
	///
	enum RBTreeSide
	{
		kRBTreeSideLeft,
		kRBTreeSideRight
	};



	/// rbtree_node_base
	///
	/// We define a rbtree_node_base separately from rbtree_node (below), because it 
	/// allows us to have non-templated operations, and it makes it so that the 
	/// rbtree anchor node doesn't carry a T with it, which would waste space and 
	/// possibly lead to surprising the user due to extra Ts existing that the user 
	/// didn't explicitly create. The downside to all of this is that it makes debug 
	/// viewing of an rbtree harder, given that the node pointers are of type 
	/// rbtree_node_base and not rbtree_node.
	///
	struct rbtree_node_base
	{
		typedef rbtree_node_base this_type;

	public:
		this_type* mpNodeRight;  // Declared first because it is used most often.
		this_type* mpNodeLeft;
		this_type* mpNodeParent;
		char       mColor;       // We only need one bit here, would be nice if we could stuff that bit somewhere else.
	};


	/// rbtree_node
	///
	template <typename Value>
	struct rbtree_node : public rbtree_node_base
	{
		Value mValue; // For set and multiset, this is the user's value, for map and multimap, this is a pair of key/value.
	};




	// rbtree_node_base functions
	//
	// These are the fundamental functions that we use to maintain the 
	// tree. The bulk of the work of the tree maintenance is done in 
	// these functions.
	//
	 rbtree_node_base* RBTreeIncrement    (const rbtree_node_base* pNode);
	 rbtree_node_base* RBTreeDecrement    (const rbtree_node_base* pNode);
	 rbtree_node_base* RBTreeGetMinChild  (const rbtree_node_base* pNode);
	 rbtree_node_base* RBTreeGetMaxChild  (const rbtree_node_base* pNode);
	 size_t            RBTreeGetBlackCount(const rbtree_node_base* pNodeTop,
		const rbtree_node_base* pNodeBottom);
	 void              RBTreeInsert       (      rbtree_node_base* pNode,
		rbtree_node_base* pNodeParent, 
		rbtree_node_base* pNodeAnchor,
		RBTreeSide insertionSide);
	 void              RBTreeErase        (      rbtree_node_base* pNode,
		rbtree_node_base* pNodeAnchor); 







	/// rbtree_iterator
	///
	template <typename T, typename Pointer, typename Reference>
	struct rbtree_iterator
	{
		typedef rbtree_iterator<T, Pointer, Reference>      this_type;
		typedef rbtree_iterator<T, T*, T&>                  iterator;
		typedef rbtree_iterator<T, const T*, const T&>      const_iterator;
		typedef size_t                                size_type;     // See config.h for the definition of size_t, which defaults to mimp::MiU32.
		typedef ptrdiff_t                                   difference_type;
		typedef T                                           value_type;
		typedef rbtree_node_base                            base_node_type;
		typedef rbtree_node<T>                              node_type;
		typedef Pointer                                     pointer;
		typedef Reference                                   reference;
		typedef EASTL_ITC_NS::bidirectional_iterator_tag    iterator_category;

	public:
		node_type* mpNode;

	public:
		rbtree_iterator();
		explicit rbtree_iterator(const node_type* pNode);
		rbtree_iterator(const iterator& x);

		reference operator*() const;
		pointer   operator->() const;

		rbtree_iterator& operator++();
		rbtree_iterator  operator++(int);

		rbtree_iterator& operator--();
		rbtree_iterator  operator--(int);

	}; // rbtree_iterator





	///////////////////////////////////////////////////////////////////////////////
	// rb_base
	//
	// This class allows us to use a generic rbtree as the basis of map, multimap,
	// set, and multiset transparently. The vital template parameters for this are 
	// the ExtractKey and the bUniqueKeys parameters.
	//
	// If the rbtree has a value type of the form pair<T1, T2> (i.e. it is a map or
	// multimap and not a set or multiset) and a key extraction policy that returns 
	// the first part of the pair, the rbtree gets a mapped_type typedef. 
	// If it satisfies those criteria and also has unique keys, then it also gets an 
	// operator[] (which only map and set have and multimap and multiset don't have).
	//
	///////////////////////////////////////////////////////////////////////////////



	/// rb_base
	/// This specialization is used for 'set'. In this case, Key and Value 
	/// will be the same as each other and ExtractKey will be mimp::use_self.
	///
	template <typename Key, typename Value, typename Compare, typename ExtractKey, bool bUniqueKeys, typename RBTree>
	struct rb_base
	{
		typedef ExtractKey extract_key;

	public:
		Compare mCompare; // To do: Make sure that empty Compare classes go away via empty base optimizations.

	public:
		rb_base() : mCompare() {}
		rb_base(const Compare& compare) : mCompare(compare) {}
	};


	/// rb_base
	/// This class is used for 'multiset'.
	/// In this case, Key and Value will be the same as each 
	/// other and ExtractKey will be mimp::use_self.
	///
	template <typename Key, typename Value, typename Compare, typename ExtractKey, typename RBTree>
	struct rb_base<Key, Value, Compare, ExtractKey, false, RBTree>
	{
		typedef ExtractKey extract_key;

	public:
		Compare mCompare; // To do: Make sure that empty Compare classes go away via empty base optimizations.

	public:
		rb_base() : mCompare() {}
		rb_base(const Compare& compare) : mCompare(compare) {}
	};


	/// rb_base
	/// This specialization is used for 'map'.
	///
	template <typename Key, typename Pair, typename Compare, typename RBTree>
	struct rb_base<Key, Pair, Compare, mimp::use_first<Pair>, true, RBTree>
	{
		typedef mimp::use_first<Pair> extract_key;

	public:
		Compare mCompare; // To do: Make sure that empty Compare classes go away via empty base optimizations.

	public:
		rb_base() : mCompare() {}
		rb_base(const Compare& compare) : mCompare(compare) {}
	};


	/// rb_base
	/// This specialization is used for 'multimap'.
	///
	template <typename Key, typename Pair, typename Compare, typename RBTree>
	struct rb_base<Key, Pair, Compare, mimp::use_first<Pair>, false, RBTree>
	{
		typedef mimp::use_first<Pair> extract_key;

	public:
		Compare mCompare; // To do: Make sure that empty Compare classes go away via empty base optimizations.

	public:
		rb_base() : mCompare() {}
		rb_base(const Compare& compare) : mCompare(compare) {}
	};





	/// rbtree
	///
	/// rbtree is the red-black tree basis for the map, multimap, set, and multiset 
	/// containers. Just about all the work of those containers is done here, and 
	/// they are merely a shell which sets template policies that govern the code
	/// generation for this rbtree.
	///
	/// This rbtree implementation is pretty much the same as all other modern 
	/// rbtree implementations, as the topic is well known and researched. We may
	/// choose to implement a "relaxed balancing" option at some point in the 
	/// future if it is deemed worthwhile. Most rbtree implementations don't do this.
	///
	/// The primary rbtree member variable is mAnchor, which is a node_type and 
	/// acts as the end node. However, like any other node, it has mpNodeLeft,
	/// mpNodeRight, and mpNodeParent members. We do the conventional trick of 
	/// assigning begin() (left-most rbtree node) to mpNodeLeft, assigning 
	/// 'end() - 1' (a.k.a. rbegin()) to mpNodeRight, and assigning the tree root
	/// node to mpNodeParent. 
	///
	/// Compare (functor): This is a comparison class which defaults to 'less'.
	/// It is a common STL thing which takes two arguments and returns true if  
	/// the first is less than the second.
	///
	/// ExtractKey (functor): This is a class which gets the key from a stored
	/// node. With map and set, the node is a pair, whereas with set and multiset
	/// the node is just the value. ExtractKey will be either mimp::use_first (map and multimap)
	/// or mimp::use_self (set and multiset).
	///
	/// bMutableIterators (bool): true if rbtree::iterator is a mutable
	/// iterator, false if iterator and const_iterator are both const iterators. 
	/// It will be true for map and multimap and false for set and multiset.
	///
	/// bUniqueKeys (bool): true if the keys are to be unique, and false if there
	/// can be multiple instances of a given key. It will be true for set and map 
	/// and false for multiset and multimap.
	///
	/// To consider: Add an option for relaxed tree balancing. This could result 
	/// in performance improvements but would require a more complicated implementation.
	///
	///////////////////////////////////////////////////////////////////////
	/// find_as
	/// In order to support the ability to have a tree of strings but
	/// be able to do efficiently lookups via char pointers (i.e. so they
	/// aren't converted to string objects), we provide the find_as
	/// function. This function allows you to do a find with a key of a
	/// type other than the tree's key type. See the find_as function
	/// for more documentation on this.
	///
	template <typename Key, typename Value, typename Compare, typename Allocator, 
		typename ExtractKey, bool bMutableIterators, bool bUniqueKeys>
	class rbtree
		: public rb_base<Key, Value, Compare, ExtractKey, bUniqueKeys, 
		rbtree<Key, Value, Compare, Allocator, ExtractKey, bMutableIterators, bUniqueKeys> >
	{
	public:
		typedef ptrdiff_t                                                                       difference_type;
		typedef size_t                                                                    size_type;     // See config.h for the definition of size_t, which defaults to mimp::MiU32.
		typedef Key                                                                             key_type;
		typedef Value                                                                           value_type;
		typedef rbtree_node<value_type>                                                         node_type;
		typedef value_type&                                                                     reference;
		typedef const value_type&                                                               const_reference;
		typedef typename type_select<bMutableIterators, 
			rbtree_iterator<value_type, value_type*, value_type&>, 
			rbtree_iterator<value_type, const value_type*, const value_type&> >::type   iterator;
		typedef rbtree_iterator<value_type, const value_type*, const value_type&>               const_iterator;
		typedef mimp::reverse_iterator<iterator>                                               reverse_iterator;
		typedef mimp::reverse_iterator<const_iterator>                                         const_reverse_iterator;

		typedef Allocator                                                                       allocator_type;
		typedef Compare                                                                         key_compare;
		typedef typename type_select<bUniqueKeys, mimp::pair<iterator, bool>, iterator>::type  insert_return_type;  // map/set::insert return a pair, multimap/multiset::iterator return an iterator.
		typedef rbtree<Key, Value, Compare, Allocator, 
			ExtractKey, bMutableIterators, bUniqueKeys>                             this_type;
		typedef rb_base<Key, Value, Compare, ExtractKey, bUniqueKeys, this_type>                base_type;
		typedef integral_constant<bool, bUniqueKeys>                                            has_unique_keys_type;
		typedef typename base_type::extract_key                                                 extract_key;

		using base_type::mCompare;

		enum
		{
			kKeyAlignment         = EASTL_ALIGN_OF(key_type),
			kKeyAlignmentOffset   = 0,                          // To do: Make sure this really is zero for all uses of this template.
			kValueAlignment       = EASTL_ALIGN_OF(value_type),
			kValueAlignmentOffset = 0                           // To fix: This offset is zero for sets and >0 for maps. Need to fix this.
		};

	public:
		rbtree_node_base  mAnchor;      /// This node acts as end() and its mpLeft points to begin(), and mpRight points to rbegin() (the last node on the right).
		size_type         mnSize;       /// Stores the count of nodes in the tree (not counting the anchor node).
		allocator_type    mAllocator;   // To do: Use base class optimization to make this go away.

	public:
		// ctor/dtor
		rbtree();
		rbtree(const allocator_type& allocator);
		rbtree(const Compare& compare, const allocator_type& allocator = EASTL_RBTREE_DEFAULT_ALLOCATOR);
		rbtree(const this_type& x);

		template <typename InputIterator>
		rbtree(InputIterator first, InputIterator last, const Compare& compare, const allocator_type& allocator = EASTL_RBTREE_DEFAULT_ALLOCATOR);

		~rbtree();

	public:
		// properties
		allocator_type& get_allocator();
		void            set_allocator(const allocator_type& allocator);

		const key_compare& key_comp() const { return mCompare; }
		key_compare&       key_comp()       { return mCompare; }

		this_type& operator=(const this_type& x);

		void swap(this_type& x);

	public: 
		// iterators
		iterator        begin();
		const_iterator  begin() const;
		iterator        end();
		const_iterator  end() const;

		reverse_iterator        rbegin();
		const_reverse_iterator  rbegin() const;
		reverse_iterator        rend();
		const_reverse_iterator  rend() const;

	public:
		bool      empty() const;
		size_type size() const;

		/// map::insert and set::insert return a pair, while multimap::insert and
		/// multiset::insert return an iterator.
		insert_return_type insert(const value_type& value);

		// C++ standard: inserts value if and only if there is no element with 
		// key equivalent to the key of t in containers with unique keys; always 
		// inserts value in containers with equivalent keys. Always returns the 
		// iterator pointing to the element with key equivalent to the key of value. 
		// iterator position is a hint pointing to where the insert should start
		// to search. However, there is a potential defect/improvement report on this behaviour:
		// LWG issue #233 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1780.html)
		// We follow the same approach as SGI STL/STLPort and use the position as
		// a forced insertion position for the value when possible.
		iterator insert(iterator position, const value_type& value);

		template <typename InputIterator>
		void insert(InputIterator first, InputIterator last);

		iterator erase(iterator position);
		iterator erase(iterator first, iterator last);

		reverse_iterator erase(reverse_iterator position);
		reverse_iterator erase(reverse_iterator first, reverse_iterator last);

		// For some reason, multiple STL versions make a specialization 
		// for erasing an array of key_types. I'm pretty sure we don't
		// need this, but just to be safe we will follow suit. 
		// The implementation is trivial. Returns void because the values
		// could well be randomly distributed throughout the tree and thus
		// a return value would be nearly meaningless.
		void erase(const key_type* first, const key_type* last);

		void clear();
		void reset();

		iterator       find(const key_type& key);
		const_iterator find(const key_type& key) const;

		/// Implements a find whereby the user supplies a comparison of a different type
		/// than the tree's value_type. A useful case of this is one whereby you have
		/// a container of string objects but want to do searches via passing in char pointers.
		/// The problem is that without this kind of find, you need to do the expensive operation
		/// of converting the char pointer to a string so it can be used as the argument to the
		/// find function.
		///
		/// Example usage (note that the compare uses string as first type and char* as second):
		///     set<string> strings;
		///     strings.find_as("hello", less_2<string, const char*>());
		///
		template <typename U, typename Compare2>
		iterator       find_as(const U& u, Compare2 compare2);

		template <typename U, typename Compare2>
		const_iterator find_as(const U& u, Compare2 compare2) const;

		iterator       lower_bound(const key_type& key);
		const_iterator lower_bound(const key_type& key) const;

		iterator       upper_bound(const key_type& key);
		const_iterator upper_bound(const key_type& key) const;

		bool validate() const;
		int  validate_iterator(const_iterator i) const;

	protected:
		node_type*  DoAllocateNode();
		void        DoFreeNode(node_type* pNode);

		node_type* DoCreateNodeFromKey(const key_type& key);
		node_type* DoCreateNode(const value_type& value);
		node_type* DoCreateNode(const node_type* pNodeSource, node_type* pNodeParent);

		node_type* DoCopySubtree(const node_type* pNodeSource, node_type* pNodeDest);
		void       DoNukeSubtree(node_type* pNode);

		// Intentionally return a pair and not an iterator for DoInsertValue(..., true_type)
		// This is because the C++ standard for map and set is to return a pair and not just an iterator.
		mimp::pair<iterator, bool> DoInsertValue(const value_type& value, true_type);  // true_type means keys are unique.
		iterator DoInsertValue(const value_type& value, false_type);                    // false_type means keys are not unique.

		mimp::pair<iterator, bool> DoInsertKey(const key_type& key, true_type);
		iterator DoInsertKey(const key_type& key, false_type);

		iterator DoInsertValue(iterator position, const value_type& value, true_type);
		iterator DoInsertValue(iterator position, const value_type& value, false_type);

		iterator DoInsertKey(iterator position, const key_type& key, true_type);
		iterator DoInsertKey(iterator position, const key_type& key, false_type);

		iterator DoInsertValueImpl(node_type* pNodeParent, const value_type& value, bool bForceToLeft);
		iterator DoInsertKeyImpl(node_type* pNodeParent, const key_type& key, bool bForceToLeft);

	}; // rbtree





	///////////////////////////////////////////////////////////////////////
	// rbtree_node_base functions
	///////////////////////////////////////////////////////////////////////

	 inline rbtree_node_base* RBTreeGetMinChild(const rbtree_node_base* pNodeBase)
	{
		while(pNodeBase->mpNodeLeft) 
			pNodeBase = pNodeBase->mpNodeLeft;
		return const_cast<rbtree_node_base*>(pNodeBase);
	}

	 inline rbtree_node_base* RBTreeGetMaxChild(const rbtree_node_base* pNodeBase)
	{
		while(pNodeBase->mpNodeRight) 
			pNodeBase = pNodeBase->mpNodeRight;
		return const_cast<rbtree_node_base*>(pNodeBase);
	}

	// The rest of the functions are non-trivial and are found in 
	// the corresponding .cpp file to this file.



	///////////////////////////////////////////////////////////////////////
	// rbtree_iterator functions
	///////////////////////////////////////////////////////////////////////

	template <typename T, typename Pointer, typename Reference>
	rbtree_iterator<T, Pointer, Reference>::rbtree_iterator()
		: mpNode(NULL) { }


	template <typename T, typename Pointer, typename Reference>
	rbtree_iterator<T, Pointer, Reference>::rbtree_iterator(const node_type* pNode)
		: mpNode(static_cast<node_type*>(const_cast<node_type*>(pNode))) { }


	template <typename T, typename Pointer, typename Reference>
	rbtree_iterator<T, Pointer, Reference>::rbtree_iterator(const iterator& x)
		: mpNode(x.mpNode) { }


	template <typename T, typename Pointer, typename Reference>
	typename rbtree_iterator<T, Pointer, Reference>::reference
		rbtree_iterator<T, Pointer, Reference>::operator*() const
	{ return mpNode->mValue; }


	template <typename T, typename Pointer, typename Reference>
	typename rbtree_iterator<T, Pointer, Reference>::pointer
		rbtree_iterator<T, Pointer, Reference>::operator->() const
	{ return &mpNode->mValue; }


	template <typename T, typename Pointer, typename Reference>
	typename rbtree_iterator<T, Pointer, Reference>::this_type&
		rbtree_iterator<T, Pointer, Reference>::operator++()
	{
		mpNode = static_cast<node_type*>(RBTreeIncrement(mpNode));
		return *this;
	}


	template <typename T, typename Pointer, typename Reference>
	typename rbtree_iterator<T, Pointer, Reference>::this_type
		rbtree_iterator<T, Pointer, Reference>::operator++(int)
	{
		this_type temp(*this);
		mpNode = static_cast<node_type*>(RBTreeIncrement(mpNode));
		return temp;
	}


	template <typename T, typename Pointer, typename Reference>
	typename rbtree_iterator<T, Pointer, Reference>::this_type&
		rbtree_iterator<T, Pointer, Reference>::operator--()
	{
		mpNode = static_cast<node_type*>(RBTreeDecrement(mpNode));
		return *this;
	}


	template <typename T, typename Pointer, typename Reference>
	typename rbtree_iterator<T, Pointer, Reference>::this_type
		rbtree_iterator<T, Pointer, Reference>::operator--(int)
	{
		this_type temp(*this);
		mpNode = static_cast<node_type*>(RBTreeDecrement(mpNode));
		return temp;
	}


	// The C++ defect report #179 requires that we support comparisons between const and non-const iterators.
	// Thus we provide additional template paremeters here to support this. The defect report does not
	// require us to support comparisons between reverse_iterators and const_reverse_iterators.
	template <typename T, typename PointerA, typename ReferenceA, typename PointerB, typename ReferenceB>
	inline bool operator==(const rbtree_iterator<T, PointerA, ReferenceA>& a, 
		const rbtree_iterator<T, PointerB, ReferenceB>& b)
	{
		return a.mpNode == b.mpNode;
	}


	template <typename T, typename PointerA, typename ReferenceA, typename PointerB, typename ReferenceB>
	inline bool operator!=(const rbtree_iterator<T, PointerA, ReferenceA>& a, 
		const rbtree_iterator<T, PointerB, ReferenceB>& b)
	{
		return a.mpNode != b.mpNode;
	}


	// We provide a version of operator!= for the case where the iterators are of the 
	// same type. This helps prevent ambiguity errors in the presence of rel_ops.
	template <typename T, typename Pointer, typename Reference>
	inline bool operator!=(const rbtree_iterator<T, Pointer, Reference>& a, 
		const rbtree_iterator<T, Pointer, Reference>& b)
	{
		return a.mpNode != b.mpNode;
	}




	///////////////////////////////////////////////////////////////////////
	// rbtree functions
	///////////////////////////////////////////////////////////////////////

	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline rbtree<K, V, C, A, E, bM, bU>::rbtree()
		: mAnchor(),
		mnSize(0),
		mAllocator(EASTL_RBTREE_DEFAULT_NAME)
	{
		reset();
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline rbtree<K, V, C, A, E, bM, bU>::rbtree(const allocator_type& allocator)
		: mAnchor(),
		mnSize(0),
		mAllocator(allocator)
	{
		reset();
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline rbtree<K, V, C, A, E, bM, bU>::rbtree(const C& compare, const allocator_type& allocator)
		: base_type(compare),
		mAnchor(),
		mnSize(0),
		mAllocator(allocator)
	{
		reset();
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline rbtree<K, V, C, A, E, bM, bU>::rbtree(const this_type& x)
		: base_type(x.mCompare),
		mAnchor(),
		mnSize(0),
		mAllocator(x.mAllocator)
	{
		reset();

		if(x.mAnchor.mpNodeParent) // mAnchor.mpNodeParent is the rb_tree root node.
		{
			mAnchor.mpNodeParent = DoCopySubtree((const node_type*)x.mAnchor.mpNodeParent, (node_type*)&mAnchor);
			mAnchor.mpNodeRight  = RBTreeGetMaxChild(mAnchor.mpNodeParent);
			mAnchor.mpNodeLeft   = RBTreeGetMinChild(mAnchor.mpNodeParent);
			mnSize               = x.mnSize;
		}
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	template <typename InputIterator>
	inline rbtree<K, V, C, A, E, bM, bU>::rbtree(InputIterator first, InputIterator last, const C& compare, const allocator_type& allocator)
		: base_type(compare),
		mAnchor(),
		mnSize(0),
		mAllocator(allocator)
	{
		reset();

			for(; first != last; ++first)
				insert(*first);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline rbtree<K, V, C, A, E, bM, bU>::~rbtree()
	{
		// Erase the entire tree. DoNukeSubtree is not a 
		// conventional erase function, as it does no rebalancing.
		DoNukeSubtree((node_type*)mAnchor.mpNodeParent);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::allocator_type&
		rbtree<K, V, C, A, E, bM, bU>::get_allocator()
	{
		return mAllocator;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline void rbtree<K, V, C, A, E, bM, bU>::set_allocator(const allocator_type& allocator)
	{
		mAllocator = allocator;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::size_type
		rbtree<K, V, C, A, E, bM, bU>::size() const
	{ return mnSize; }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline bool rbtree<K, V, C, A, E, bM, bU>::empty() const
	{ return (mnSize == 0); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::begin()
	{ return iterator(static_cast<node_type*>(mAnchor.mpNodeLeft)); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::const_iterator
		rbtree<K, V, C, A, E, bM, bU>::begin() const
	{ return const_iterator(static_cast<node_type*>(const_cast<rbtree_node_base*>(mAnchor.mpNodeLeft))); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::end()
	{ return iterator(static_cast<node_type*>(&mAnchor)); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::const_iterator
		rbtree<K, V, C, A, E, bM, bU>::end() const
	{ return const_iterator(static_cast<node_type*>(const_cast<rbtree_node_base*>(&mAnchor))); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::reverse_iterator
		rbtree<K, V, C, A, E, bM, bU>::rbegin()
	{ return reverse_iterator(end()); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::const_reverse_iterator
		rbtree<K, V, C, A, E, bM, bU>::rbegin() const
	{ return const_reverse_iterator(end()); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::reverse_iterator
		rbtree<K, V, C, A, E, bM, bU>::rend()
	{ return reverse_iterator(begin()); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::const_reverse_iterator
		rbtree<K, V, C, A, E, bM, bU>::rend() const
	{ return const_reverse_iterator(begin()); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::this_type&
		rbtree<K, V, C, A, E, bM, bU>::operator=(const this_type& x)
	{
		if(this != &x)
		{
			clear();

#if EASTL_ALLOCATOR_COPY_ENABLED
			mAllocator = x.mAllocator;
#endif

			base_type::mCompare = x.mCompare;

			if(x.mAnchor.mpNodeParent) // mAnchor.mpNodeParent is the rb_tree root node.
			{
				mAnchor.mpNodeParent = DoCopySubtree((const node_type*)x.mAnchor.mpNodeParent, (node_type*)&mAnchor);
				mAnchor.mpNodeRight  = RBTreeGetMaxChild(mAnchor.mpNodeParent);
				mAnchor.mpNodeLeft   = RBTreeGetMinChild(mAnchor.mpNodeParent);
				mnSize               = x.mnSize;
			}
		}
		return *this;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	void rbtree<K, V, C, A, E, bM, bU>::swap(this_type& x)
	{
		if(mAllocator == x.mAllocator) // If allocators are equivalent...
		{
			// Most of our members can be exchaged by a basic swap:
			// We leave mAllocator as-is.
			mimp::swap(mnSize,              x.mnSize);
			mimp::swap(base_type::mCompare, x.mCompare);

			// However, because our anchor node is a part of our class instance and not 
			// dynamically allocated, we can't do a swap of it but must do a more elaborate
			// procedure. This is the downside to having the mAnchor be like this, but 
			// otherwise we consider it a good idea to avoid allocating memory for a 
			// nominal container instance.

			// We optimize for the expected most common case: both pointers being non-null.
			if(mAnchor.mpNodeParent && x.mAnchor.mpNodeParent) // If both pointers are non-null...
			{
				mimp::swap(mAnchor.mpNodeRight,  x.mAnchor.mpNodeRight);
				mimp::swap(mAnchor.mpNodeLeft,   x.mAnchor.mpNodeLeft);
				mimp::swap(mAnchor.mpNodeParent, x.mAnchor.mpNodeParent);

				// We need to fix up the anchors to point to themselves (we can't just swap them).
				mAnchor.mpNodeParent->mpNodeParent   = &mAnchor;
				x.mAnchor.mpNodeParent->mpNodeParent = &x.mAnchor;
			}
			else if(mAnchor.mpNodeParent)
			{
				x.mAnchor.mpNodeRight  = mAnchor.mpNodeRight;
				x.mAnchor.mpNodeLeft   = mAnchor.mpNodeLeft;
				x.mAnchor.mpNodeParent = mAnchor.mpNodeParent;
				x.mAnchor.mpNodeParent->mpNodeParent = &x.mAnchor;

				// We need to fix up our anchor to point it itself (we can't have it swap with x).
				mAnchor.mpNodeRight  = &mAnchor;
				mAnchor.mpNodeLeft   = &mAnchor;
				mAnchor.mpNodeParent = NULL;
			}
			else if(x.mAnchor.mpNodeParent)
			{
				mAnchor.mpNodeRight  = x.mAnchor.mpNodeRight;
				mAnchor.mpNodeLeft   = x.mAnchor.mpNodeLeft;
				mAnchor.mpNodeParent = x.mAnchor.mpNodeParent;
				mAnchor.mpNodeParent->mpNodeParent = &mAnchor;

				// We need to fix up x's anchor to point it itself (we can't have it swap with us).
				x.mAnchor.mpNodeRight  = &x.mAnchor;
				x.mAnchor.mpNodeLeft   = &x.mAnchor;
				x.mAnchor.mpNodeParent = NULL;
			} // Else both are NULL and there is nothing to do.
		}
		else
		{
			const this_type temp(*this); // Can't call mimp::swap because that would
			*this = x;                   // itself call this member swap function.
			x     = temp;
		}
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::insert_return_type // map/set::insert return a pair, multimap/multiset::iterator return an iterator.
		rbtree<K, V, C, A, E, bM, bU>::insert(const value_type& value)
	{ return DoInsertValue(value, has_unique_keys_type()); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::insert(iterator position, const value_type& value)
	{ return DoInsertValue(position, value, has_unique_keys_type()); }


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	mimp::pair<typename rbtree<K, V, C, A, E, bM, bU>::iterator, bool>
		rbtree<K, V, C, A, E, bM, bU>::DoInsertValue(const value_type& value, true_type) // true_type means keys are unique.
	{
		// This is the pathway for insertion of unique keys (map and set, but not multimap and multiset).
		// Note that we return a pair and not an iterator. This is because the C++ standard for map
		// and set is to return a pair and not just an iterator.
		extract_key extractKey;

		node_type* pCurrent    = (node_type*)mAnchor.mpNodeParent; // Start with the root node.
		node_type* pLowerBound = (node_type*)&mAnchor;             // Set it to the container end for now.
		node_type* pParent;                                        // This will be where we insert the new node.

		bool bValueLessThanNode = true; // If the tree is empty, this will result in an insertion at the front.

		// Find insertion position of the value. This will either be a position which 
		// already contains the value, a position which is greater than the value or
		// end(), which we treat like a position which is greater than the value.
		while(EASTL_LIKELY(pCurrent)) // Do a walk down the tree.
		{
			bValueLessThanNode = mCompare(extractKey(value), extractKey(pCurrent->mValue));
			pLowerBound        = pCurrent;

			if(bValueLessThanNode)
			{
				EASTL_VALIDATE_COMPARE(!mCompare(extractKey(pCurrent->mValue), extractKey(value))); // Validate that the compare function is sane.
				pCurrent = (node_type*)pCurrent->mpNodeLeft;
			}
			else
				pCurrent = (node_type*)pCurrent->mpNodeRight;
		}

		pParent = pLowerBound; // pLowerBound is actually upper bound right now (i.e. it is > value instead of <=), but we will make it the lower bound below.

		if(bValueLessThanNode) // If we ended up on the left side of the last parent node...
		{
			if(EASTL_LIKELY(pLowerBound != (node_type*)mAnchor.mpNodeLeft)) // If the tree was empty or if we otherwise need to insert at the very front of the tree...
			{
				// At this point, pLowerBound points to a node which is > than value.
				// Move it back by one, so that it points to a node which is <= value.
				pLowerBound = (node_type*)RBTreeDecrement(pLowerBound);
			}
			else
			{
				const iterator itResult(DoInsertValueImpl(pLowerBound, value, false));
				return pair<iterator, bool>(itResult, true);
			}
		}

		// Since here we require values to be unique, we will do nothing if the value already exists.
		if(mCompare(extractKey(pLowerBound->mValue), extractKey(value))) // If the node is < the value (i.e. if value is >= the node)...
		{
			EASTL_VALIDATE_COMPARE(!mCompare(extractKey(value), extractKey(pLowerBound->mValue))); // Validate that the compare function is sane.
			const iterator itResult(DoInsertValueImpl(pParent, value, false));
			return pair<iterator, bool>(itResult, true);
		}

		// The item already exists (as found by the compare directly above), so return false.
		return pair<iterator, bool>(iterator(pLowerBound), false);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::DoInsertValue(const value_type& value, false_type) // false_type means keys are not unique.
	{
		// This is the pathway for insertion of non-unique keys (multimap and multiset, but not map and set).
		node_type* pCurrent  = (node_type*)mAnchor.mpNodeParent; // Start with the root node.
		node_type* pRangeEnd = (node_type*)&mAnchor;             // Set it to the container end for now.
		extract_key extractKey;

		while(pCurrent)
		{
			pRangeEnd = pCurrent;

			if(mCompare(extractKey(value), extractKey(pCurrent->mValue)))
			{
				EASTL_VALIDATE_COMPARE(!mCompare(extractKey(pCurrent->mValue), extractKey(value))); // Validate that the compare function is sane.
				pCurrent = (node_type*)pCurrent->mpNodeLeft;
			}
			else
				pCurrent = (node_type*)pCurrent->mpNodeRight;
		}

		return DoInsertValueImpl(pRangeEnd, value, false);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	mimp::pair<typename rbtree<K, V, C, A, E, bM, bU>::iterator, bool>
		rbtree<K, V, C, A, E, bM, bU>::DoInsertKey(const key_type& key, true_type) // true_type means keys are unique.
	{
		// This code is essentially a slightly modified copy of the the rbtree::insert 
		// function whereby this version takes a key and not a full value_type.
		extract_key extractKey;

		node_type* pCurrent    = (node_type*)mAnchor.mpNodeParent; // Start with the root node.
		node_type* pLowerBound = (node_type*)&mAnchor;             // Set it to the container end for now.
		node_type* pParent;                                        // This will be where we insert the new node.

		bool bValueLessThanNode = true; // If the tree is empty, this will result in an insertion at the front.

		// Find insertion position of the value. This will either be a position which 
		// already contains the value, a position which is greater than the value or
		// end(), which we treat like a position which is greater than the value.
		while(EASTL_LIKELY(pCurrent)) // Do a walk down the tree.
		{
			bValueLessThanNode = mCompare(key, extractKey(pCurrent->mValue));
			pLowerBound        = pCurrent;

			if(bValueLessThanNode)
			{
				EASTL_VALIDATE_COMPARE(!mCompare(extractKey(pCurrent->mValue), key)); // Validate that the compare function is sane.
				pCurrent = (node_type*)pCurrent->mpNodeLeft;
			}
			else
				pCurrent = (node_type*)pCurrent->mpNodeRight;
		}

		pParent = pLowerBound; // pLowerBound is actually upper bound right now (i.e. it is > value instead of <=), but we will make it the lower bound below.

		if(bValueLessThanNode) // If we ended up on the left side of the last parent node...
		{
			if(EASTL_LIKELY(pLowerBound != (node_type*)mAnchor.mpNodeLeft)) // If the tree was empty or if we otherwise need to insert at the very front of the tree...
			{
				// At this point, pLowerBound points to a node which is > than value.
				// Move it back by one, so that it points to a node which is <= value.
				pLowerBound = (node_type*)RBTreeDecrement(pLowerBound);
			}
			else
			{
				const iterator itResult(DoInsertKeyImpl(pLowerBound, key, false));
				return pair<iterator, bool>(itResult, true);
			}
		}

		// Since here we require values to be unique, we will do nothing if the value already exists.
		if(mCompare(extractKey(pLowerBound->mValue), key)) // If the node is < the value (i.e. if value is >= the node)...
		{
			EASTL_VALIDATE_COMPARE(!mCompare(key, extractKey(pLowerBound->mValue))); // Validate that the compare function is sane.
			const iterator itResult(DoInsertKeyImpl(pParent, key, false));
			return pair<iterator, bool>(itResult, true);
		}

		// The item already exists (as found by the compare directly above), so return false.
		return pair<iterator, bool>(iterator(pLowerBound), false);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::DoInsertKey(const key_type& key, false_type) // false_type means keys are not unique.
	{
		// This is the pathway for insertion of non-unique keys (multimap and multiset, but not map and set).
		node_type* pCurrent  = (node_type*)mAnchor.mpNodeParent; // Start with the root node.
		node_type* pRangeEnd = (node_type*)&mAnchor;             // Set it to the container end for now.
		extract_key extractKey;

		while(pCurrent)
		{
			pRangeEnd = pCurrent;

			if(mCompare(key, extractKey(pCurrent->mValue)))
			{
				EASTL_VALIDATE_COMPARE(!mCompare(extractKey(pCurrent->mValue), key)); // Validate that the compare function is sane.
				pCurrent = (node_type*)pCurrent->mpNodeLeft;
			}
			else
				pCurrent = (node_type*)pCurrent->mpNodeRight;
		}

		return DoInsertKeyImpl(pRangeEnd, key, false);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::DoInsertValue(iterator position, const value_type& value, true_type) // true_type means keys are unique.
	{
		// This is the pathway for insertion of unique keys (map and set, but not multimap and multiset).
		//
		// We follow the same approach as SGI STL/STLPort and use the position as
		// a forced insertion position for the value when possible.
		extract_key extractKey;

		if((position.mpNode != mAnchor.mpNodeRight) && (position.mpNode != &mAnchor)) // If the user specified a specific insertion position...
		{
			iterator itNext(position);
			++itNext;

			// To consider: Change this so that 'position' specifies the position after 
			// where the insertion goes and not the position before where the insertion goes.
			// Doing so would make this more in line with user expectations and with LWG #233.
			const bool bPositionLessThanValue = mCompare(extractKey(position.mpNode->mValue), extractKey(value));

			if(bPositionLessThanValue) // If (value > *position)...
			{
				EASTL_VALIDATE_COMPARE(!mCompare(extractKey(value), extractKey(position.mpNode->mValue))); // Validate that the compare function is sane.

				const bool bValueLessThanNext = mCompare(extractKey(value), extractKey(itNext.mpNode->mValue));

				if(bValueLessThanNext) // if (value < *itNext)...
				{
					EASTL_VALIDATE_COMPARE(!mCompare(extractKey(itNext.mpNode->mValue), extractKey(value))); // Validate that the compare function is sane.

					if(position.mpNode->mpNodeRight)
						return DoInsertValueImpl(itNext.mpNode, value, true);
					return DoInsertValueImpl(position.mpNode, value, false);
				}
			}

			return DoInsertValue(value, has_unique_keys_type()).first;
		}

		if(mnSize && mCompare(extractKey(((node_type*)mAnchor.mpNodeRight)->mValue), extractKey(value)))
		{
			EASTL_VALIDATE_COMPARE(!mCompare(extractKey(value), extractKey(((node_type*)mAnchor.mpNodeRight)->mValue))); // Validate that the compare function is sane.
			return DoInsertValueImpl((node_type*)mAnchor.mpNodeRight, value, false);
		}

		return DoInsertValue(value, has_unique_keys_type()).first;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::DoInsertValue(iterator position, const value_type& value, false_type) // false_type means keys are not unique.
	{
		// This is the pathway for insertion of non-unique keys (multimap and multiset, but not map and set).
		//
		// We follow the same approach as SGI STL/STLPort and use the position as
		// a forced insertion position for the value when possible.
		extract_key extractKey;

		if((position.mpNode != mAnchor.mpNodeRight) && (position.mpNode != &mAnchor)) // If the user specified a specific insertion position...
		{
			iterator itNext(position);
			++itNext;

			// To consider: Change this so that 'position' specifies the position after 
			// where the insertion goes and not the position before where the insertion goes.
			// Doing so would make this more in line with user expectations and with LWG #233.

			if(!mCompare(extractKey(value), extractKey(position.mpNode->mValue)) && // If value >= *position && 
				!mCompare(extractKey(itNext.mpNode->mValue), extractKey(value)))     // if value <= *itNext...
			{
				if(position.mpNode->mpNodeRight) // If there are any nodes to the right... [this expression will always be true as long as we aren't at the end()]
					return DoInsertValueImpl(itNext.mpNode, value, true); // Specifically insert in front of (to the left of) itNext (and thus after 'position').
				return DoInsertValueImpl(position.mpNode, value, false);
			}

			return DoInsertValue(value, has_unique_keys_type()); // If the above specified hint was not useful, then we do a regular insertion.
		}

		// This pathway shouldn't be commonly executed, as the user shouldn't be calling 
		// this hinted version of insert if the user isn't providing a useful hint.

		if(mnSize && !mCompare(extractKey(value), extractKey(((node_type*)mAnchor.mpNodeRight)->mValue))) // If we are non-empty and the value is >= the last node...
			return DoInsertValueImpl((node_type*)mAnchor.mpNodeRight, value, false); // Insert after the last node (doesn't matter if we force left or not).

		return DoInsertValue(value, has_unique_keys_type()); // We are empty or we are inserting at the end.
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::DoInsertKey(iterator position, const key_type& key, true_type) // true_type means keys are unique.
	{
		// This is the pathway for insertion of unique keys (map and set, but not multimap and multiset).
		//
		// We follow the same approach as SGI STL/STLPort and use the position as
		// a forced insertion position for the value when possible.
		extract_key extractKey;

		if((position.mpNode != mAnchor.mpNodeRight) && (position.mpNode != &mAnchor)) // If the user specified a specific insertion position...
		{
			iterator itNext(position);
			++itNext;

			// To consider: Change this so that 'position' specifies the position after 
			// where the insertion goes and not the position before where the insertion goes.
			// Doing so would make this more in line with user expectations and with LWG #233.
			const bool bPositionLessThanValue = mCompare(extractKey(position.mpNode->mValue), key);

			if(bPositionLessThanValue) // If (value > *position)...
			{
				EASTL_VALIDATE_COMPARE(!mCompare(key, extractKey(position.mpNode->mValue))); // Validate that the compare function is sane.

				const bool bValueLessThanNext = mCompare(key, extractKey(itNext.mpNode->mValue));

				if(bValueLessThanNext) // If value < *itNext...
				{
					EASTL_VALIDATE_COMPARE(!mCompare(extractKey(itNext.mpNode->mValue), key)); // Validate that the compare function is sane.

					if(position.mpNode->mpNodeRight)
						return DoInsertKeyImpl(itNext.mpNode, key, true);
					return DoInsertKeyImpl(position.mpNode, key, false);
				}
			}

			return DoInsertKey(key, has_unique_keys_type()).first;
		}

		if(mnSize && mCompare(extractKey(((node_type*)mAnchor.mpNodeRight)->mValue), key))
		{
			EASTL_VALIDATE_COMPARE(!mCompare(key, extractKey(((node_type*)mAnchor.mpNodeRight)->mValue))); // Validate that the compare function is sane.
			return DoInsertKeyImpl((node_type*)mAnchor.mpNodeRight, key, false);
		}

		return DoInsertKey(key, has_unique_keys_type()).first;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::DoInsertKey(iterator position, const key_type& key, false_type) // false_type means keys are not unique.
	{
		// This is the pathway for insertion of non-unique keys (multimap and multiset, but not map and set).
		//
		// We follow the same approach as SGI STL/STLPort and use the position as
		// a forced insertion position for the value when possible.
		extract_key extractKey;

		if((position.mpNode != mAnchor.mpNodeRight) && (position.mpNode != &mAnchor)) // If the user specified a specific insertion position...
		{
			iterator itNext(position);
			++itNext;

			// To consider: Change this so that 'position' specifies the position after 
			// where the insertion goes and not the position before where the insertion goes.
			// Doing so would make this more in line with user expectations and with LWG #233.
			if(!mCompare(key, extractKey(position.mpNode->mValue)) && // If value >= *position && 
				!mCompare(extractKey(itNext.mpNode->mValue), key))     // if value <= *itNext...
			{
				if(position.mpNode->mpNodeRight) // If there are any nodes to the right... [this expression will always be true as long as we aren't at the end()]
					return DoInsertKeyImpl(itNext.mpNode, key, true); // Specifically insert in front of (to the left of) itNext (and thus after 'position').
				return DoInsertKeyImpl(position.mpNode, key, false);
			}

			return DoInsertKey(key, has_unique_keys_type()); // If the above specified hint was not useful, then we do a regular insertion.
		}

		// This pathway shouldn't be commonly executed, as the user shouldn't be calling 
		// this hinted version of insert if the user isn't providing a useful hint.
		if(mnSize && !mCompare(key, extractKey(((node_type*)mAnchor.mpNodeRight)->mValue))) // If we are non-empty and the value is >= the last node...
			return DoInsertKeyImpl((node_type*)mAnchor.mpNodeRight, key, false); // Insert after the last node (doesn't matter if we force left or not).

		return DoInsertKey(key, has_unique_keys_type()); // We are empty or we are inserting at the end.
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::DoInsertValueImpl(node_type* pNodeParent, const value_type& value, bool bForceToLeft)
	{
		RBTreeSide side;
		extract_key extractKey;

		// The reason we may want to have bForceToLeft == true is that pNodeParent->mValue and value may be equal.
		// In that case it doesn't matter what side we insert on, except that the C++ LWG #233 improvement report
		// suggests that we should use the insert hint position to force an ordering. So that's what we do.
		if(bForceToLeft || (pNodeParent == &mAnchor) || mCompare(extractKey(value), extractKey(pNodeParent->mValue)))
			side = kRBTreeSideLeft;
		else
			side = kRBTreeSideRight;

		node_type* const pNodeNew = DoCreateNode(value); // Note that pNodeNew->mpLeft, mpRight, mpParent, will be uninitialized.
		RBTreeInsert(pNodeNew, pNodeParent, &mAnchor, side);
		mnSize++;

		return iterator(pNodeNew);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::DoInsertKeyImpl(node_type* pNodeParent, const key_type& key, bool bForceToLeft)
	{
		RBTreeSide side;
		extract_key extractKey;

		// The reason we may want to have bForceToLeft == true is that pNodeParent->mValue and value may be equal.
		// In that case it doesn't matter what side we insert on, except that the C++ LWG #233 improvement report
		// suggests that we should use the insert hint position to force an ordering. So that's what we do.
		if(bForceToLeft || (pNodeParent == &mAnchor) || mCompare(key, extractKey(pNodeParent->mValue)))
			side = kRBTreeSideLeft;
		else
			side = kRBTreeSideRight;

		node_type* const pNodeNew = DoCreateNodeFromKey(key); // Note that pNodeNew->mpLeft, mpRight, mpParent, will be uninitialized.
		RBTreeInsert(pNodeNew, pNodeParent, &mAnchor, side);
		mnSize++;

		return iterator(pNodeNew);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	template <typename InputIterator>
	void rbtree<K, V, C, A, E, bM, bU>::insert(InputIterator first, InputIterator last)
	{
		for( ; first != last; ++first)
			DoInsertValue(*first, has_unique_keys_type()); // Or maybe we should call 'insert(end(), *first)' instead. If the first-last range was sorted then this might make some sense.
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline void rbtree<K, V, C, A, E, bM, bU>::clear()
	{
		// Erase the entire tree. DoNukeSubtree is not a 
		// conventional erase function, as it does no rebalancing.
		DoNukeSubtree((node_type*)mAnchor.mpNodeParent);
		reset();
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline void rbtree<K, V, C, A, E, bM, bU>::reset()
	{
		// The reset function is a special extension function which unilaterally 
		// resets the container to an empty state without freeing the memory of 
		// the contained objects. This is useful for very quickly tearing down a 
		// container built into scratch memory.
		mAnchor.mpNodeRight  = &mAnchor;
		mAnchor.mpNodeLeft   = &mAnchor;
		mAnchor.mpNodeParent = NULL;
		mAnchor.mColor       = kRBTreeColorRed;
		mnSize               = 0;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::erase(iterator position)
	{
		const iterator iErase(position);
		--mnSize; // Interleave this between the two references to itNext. We expect no exceptions to occur during the code below.
		++position;
		RBTreeErase(iErase.mpNode, &mAnchor);
		DoFreeNode(iErase.mpNode);
		return position;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::erase(iterator first, iterator last)
	{
		// We expect that if the user means to clear the container, they will call clear.
		if(EASTL_LIKELY((first.mpNode != mAnchor.mpNodeLeft) || (last.mpNode != &mAnchor))) // If (first != begin or last != end) ...
		{
			// Basic implementation:
			while(first != last)
				first = erase(first);
			return first;

			// Inlined implementation:
			//size_type n = 0;
			//while(first != last)
			//{
			//    const iterator itErase(first);
			//    ++n;
			//    ++first;
			//    RBTreeErase(itErase.mpNode, &mAnchor);
			//    DoFreeNode(itErase.mpNode);
			//}
			//mnSize -= n;
			//return first;
		}

		clear();
		return iterator((node_type*)&mAnchor); // Same as: return end();
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::reverse_iterator
		rbtree<K, V, C, A, E, bM, bU>::erase(reverse_iterator position)
	{
		return reverse_iterator(erase((++position).base()));
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::reverse_iterator
		rbtree<K, V, C, A, E, bM, bU>::erase(reverse_iterator first, reverse_iterator last)
	{
		// Version which erases in order from first to last.
		// difference_type i(first.base() - last.base());
		// while(i--)
		//     first = erase(first);
		// return first;

		// Version which erases in order from last to first, but is slightly more efficient:
		return reverse_iterator(erase((++last).base(), (++first).base()));
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline void rbtree<K, V, C, A, E, bM, bU>::erase(const key_type* first, const key_type* last)
	{
		// We have no choice but to run a loop like this, as the first/last range could
		// have values that are discontiguously located in the tree. And some may not 
		// even be in the tree.
		while(first != last)
			erase(*first++);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::find(const key_type& key)
	{
		// To consider: Implement this instead via calling lower_bound and 
		// inspecting the result. The following is an implementation of this:
		//    const iterator it(lower_bound(key));
		//    return ((it.mpNode == &mAnchor) || mCompare(key, extractKey(it.mpNode->mValue))) ? iterator(&mAnchor) : it;
		// We don't currently implement the above because in practice people tend to call 
		// find a lot with trees, but very uncommonly call lower_bound.
		extract_key extractKey;

		node_type* pCurrent  = (node_type*)mAnchor.mpNodeParent; // Start with the root node.
		node_type* pRangeEnd = (node_type*)&mAnchor;             // Set it to the container end for now.

		while(EASTL_LIKELY(pCurrent)) // Do a walk down the tree.
		{
			if(EASTL_LIKELY(!mCompare(extractKey(pCurrent->mValue), key))) // If pCurrent is >= key...
			{
				pRangeEnd = pCurrent;
				pCurrent  = (node_type*)pCurrent->mpNodeLeft;
			}
			else
			{
				EASTL_VALIDATE_COMPARE(!mCompare(key, extractKey(pCurrent->mValue))); // Validate that the compare function is sane.
				pCurrent  = (node_type*)pCurrent->mpNodeRight;
			}
		}

		if(EASTL_LIKELY((pRangeEnd != &mAnchor) && !mCompare(key, extractKey(pRangeEnd->mValue))))
			return iterator(pRangeEnd);
		return iterator((node_type*)&mAnchor);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::const_iterator
		rbtree<K, V, C, A, E, bM, bU>::find(const key_type& key) const
	{
		typedef rbtree<K, V, C, A, E, bM, bU> rbtree_type;
		return const_iterator(const_cast<rbtree_type*>(this)->find(key));
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	template <typename U, typename Compare2>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::find_as(const U& u, Compare2 compare2)
	{
		extract_key extractKey;

		node_type* pCurrent  = (node_type*)mAnchor.mpNodeParent; // Start with the root node.
		node_type* pRangeEnd = (node_type*)&mAnchor;             // Set it to the container end for now.

		while(EASTL_LIKELY(pCurrent)) // Do a walk down the tree.
		{
			if(EASTL_LIKELY(!compare2(extractKey(pCurrent->mValue), u))) // If pCurrent is >= u...
			{
				pRangeEnd = pCurrent;
				pCurrent  = (node_type*)pCurrent->mpNodeLeft;
			}
			else
			{
				EASTL_VALIDATE_COMPARE(!compare2(u, extractKey(pCurrent->mValue))); // Validate that the compare function is sane.
				pCurrent  = (node_type*)pCurrent->mpNodeRight;
			}
		}

		if(EASTL_LIKELY((pRangeEnd != &mAnchor) && !compare2(u, extractKey(pRangeEnd->mValue))))
			return iterator(pRangeEnd);
		return iterator((node_type*)&mAnchor);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	template <typename U, typename Compare2>
	inline typename rbtree<K, V, C, A, E, bM, bU>::const_iterator
		rbtree<K, V, C, A, E, bM, bU>::find_as(const U& u, Compare2 compare2) const
	{
		typedef rbtree<K, V, C, A, E, bM, bU> rbtree_type;
		return const_iterator(const_cast<rbtree_type*>(this)->find_as(u, compare2));
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::lower_bound(const key_type& key)
	{
		extract_key extractKey;

		node_type* pCurrent  = (node_type*)mAnchor.mpNodeParent; // Start with the root node.
		node_type* pRangeEnd = (node_type*)&mAnchor;             // Set it to the container end for now.

		while(EASTL_LIKELY(pCurrent)) // Do a walk down the tree.
		{
			if(EASTL_LIKELY(!mCompare(extractKey(pCurrent->mValue), key))) // If pCurrent is >= key...
			{
				pRangeEnd = pCurrent;
				pCurrent  = (node_type*)pCurrent->mpNodeLeft;
			}
			else
			{
				EASTL_VALIDATE_COMPARE(!mCompare(key, extractKey(pCurrent->mValue))); // Validate that the compare function is sane.
				pCurrent  = (node_type*)pCurrent->mpNodeRight;
			}
		}

		return iterator(pRangeEnd);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::const_iterator
		rbtree<K, V, C, A, E, bM, bU>::lower_bound(const key_type& key) const
	{
		typedef rbtree<K, V, C, A, E, bM, bU> rbtree_type;
		return const_iterator(const_cast<rbtree_type*>(this)->lower_bound(key));
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::iterator
		rbtree<K, V, C, A, E, bM, bU>::upper_bound(const key_type& key)
	{
		extract_key extractKey;

		node_type* pCurrent  = (node_type*)mAnchor.mpNodeParent; // Start with the root node.
		node_type* pRangeEnd = (node_type*)&mAnchor;             // Set it to the container end for now.

		while(EASTL_LIKELY(pCurrent)) // Do a walk down the tree.
		{
			if(EASTL_LIKELY(mCompare(key, extractKey(pCurrent->mValue)))) // If key is < pCurrent...
			{
				EASTL_VALIDATE_COMPARE(!mCompare(extractKey(pCurrent->mValue), key)); // Validate that the compare function is sane.
				pRangeEnd = pCurrent;
				pCurrent  = (node_type*)pCurrent->mpNodeLeft;
			}
			else
				pCurrent  = (node_type*)pCurrent->mpNodeRight;
		}

		return iterator(pRangeEnd);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::const_iterator
		rbtree<K, V, C, A, E, bM, bU>::upper_bound(const key_type& key) const
	{
		typedef rbtree<K, V, C, A, E, bM, bU> rbtree_type;
		return const_iterator(const_cast<rbtree_type*>(this)->upper_bound(key));
	}


	// To do: Move this validate function entirely to a template-less implementation.
	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	bool rbtree<K, V, C, A, E, bM, bU>::validate() const
	{
		// Red-black trees have the following canonical properties which we validate here:
		//   1 Every node is either red or black.
		//   2 Every leaf (NULL) is black by defintion. Any number of black nodes may appear in a sequence. 
		//   3 If a node is red, then both its children are black. Thus, on any path from 
		//     the root to a leaf, red nodes must not be adjacent.
		//   4 Every simple path from a node to a descendant leaf contains the same number of black nodes.
		//   5 The mnSize member of the tree must equal the number of nodes in the tree.
		//   6 The tree is sorted as per a conventional binary tree.
		//   7 The comparison function is sane; it obeys strict weak ordering. If mCompare(a,b) is true, then mCompare(b,a) must be false. Both cannot be true.

		extract_key extractKey;

		if(mnSize)
		{
			// Verify basic integrity.
			//if(!mAnchor.mpNodeParent || (mAnchor.mpNodeLeft == mAnchor.mpNodeRight))
			//    return false;             // Fix this for case of empty tree.

			if(mAnchor.mpNodeLeft != RBTreeGetMinChild(mAnchor.mpNodeParent))
				return false;

			if(mAnchor.mpNodeRight != RBTreeGetMaxChild(mAnchor.mpNodeParent))
				return false;

			const size_t nBlackCount   = RBTreeGetBlackCount(mAnchor.mpNodeParent, mAnchor.mpNodeLeft);
			size_type    nIteratedSize = 0;

			for(const_iterator it = begin(); it != end(); ++it, ++nIteratedSize)
			{
				const node_type* const pNode      = (const node_type*)it.mpNode;
				const node_type* const pNodeRight = (const node_type*)pNode->mpNodeRight;
				const node_type* const pNodeLeft  = (const node_type*)pNode->mpNodeLeft;

				// Verify #7 above.
				if(pNodeRight && mCompare(extractKey(pNodeRight->mValue), extractKey(pNode->mValue)) && mCompare(extractKey(pNode->mValue), extractKey(pNodeRight->mValue))) // Validate that the compare function is sane.
					return false;

				// Verify #7 above.
				if(pNodeLeft && mCompare(extractKey(pNodeLeft->mValue), extractKey(pNode->mValue)) && mCompare(extractKey(pNode->mValue), extractKey(pNodeLeft->mValue))) // Validate that the compare function is sane.
					return false;

				// Verify item #1 above.
				if((pNode->mColor != kRBTreeColorRed) && (pNode->mColor != kRBTreeColorBlack))
					return false;

				// Verify item #3 above.
				if(pNode->mColor == kRBTreeColorRed)
				{
					if((pNodeRight && (pNodeRight->mColor == kRBTreeColorRed)) ||
						(pNodeLeft  && (pNodeLeft->mColor  == kRBTreeColorRed)))
						return false;
				}

				// Verify item #6 above.
				if(pNodeRight && mCompare(extractKey(pNodeRight->mValue), extractKey(pNode->mValue)))
					return false;

				if(pNodeLeft && mCompare(extractKey(pNode->mValue), extractKey(pNodeLeft->mValue)))
					return false;

				if(!pNodeRight && !pNodeLeft) // If we are at a bottom node of the tree...
				{
					// Verify item #4 above.
					if(RBTreeGetBlackCount(mAnchor.mpNodeParent, pNode) != nBlackCount)
						return false;
				}
			}

			// Verify item #5 above.
			if(nIteratedSize != mnSize)
				return false;

			return true;
		}
		else
		{
			if((mAnchor.mpNodeLeft != &mAnchor) || (mAnchor.mpNodeRight != &mAnchor))
				return false;
		}

		return true;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline int rbtree<K, V, C, A, E, bM, bU>::validate_iterator(const_iterator i) const
	{
		// To do: Come up with a more efficient mechanism of doing this.

		for(const_iterator temp = begin(), tempEnd = end(); temp != tempEnd; ++temp)
		{
			if(temp == i)
				return (isf_valid | isf_current | isf_can_dereference);
		}

		if(i == end())
			return (isf_valid | isf_current); 

		return isf_none;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline typename rbtree<K, V, C, A, E, bM, bU>::node_type*
		rbtree<K, V, C, A, E, bM, bU>::DoAllocateNode()
	{
		return (node_type*)allocate_memory(mAllocator, sizeof(node_type), kValueAlignment, kValueAlignmentOffset);
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	inline void rbtree<K, V, C, A, E, bM, bU>::DoFreeNode(node_type* pNode)
	{
		pNode->~node_type();
		EASTLFree(mAllocator, pNode, sizeof(node_type));
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::node_type*
		rbtree<K, V, C, A, E, bM, bU>::DoCreateNodeFromKey(const key_type& key)
	{
		// Note that this function intentionally leaves the node pointers uninitialized.
		// The caller would otherwise just turn right around and modify them, so there's
		// no point in us initializing them to anything (except in a debug build).
		node_type* const pNode = DoAllocateNode();

			::new(&pNode->mValue) value_type(key);

#if EASTL_DEBUG
		pNode->mpNodeRight  = NULL;
		pNode->mpNodeLeft   = NULL;
		pNode->mpNodeParent = NULL;
		pNode->mColor       = kRBTreeColorBlack;
#endif

		return pNode;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::node_type*
		rbtree<K, V, C, A, E, bM, bU>::DoCreateNode(const value_type& value)
	{
		// Note that this function intentionally leaves the node pointers uninitialized.
		// The caller would otherwise just turn right around and modify them, so there's
		// no point in us initializing them to anything (except in a debug build).
		node_type* const pNode = DoAllocateNode();

			::new(&pNode->mValue) value_type(value);
#if EASTL_DEBUG
		pNode->mpNodeRight  = NULL;
		pNode->mpNodeLeft   = NULL;
		pNode->mpNodeParent = NULL;
		pNode->mColor       = kRBTreeColorBlack;
#endif

		return pNode;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::node_type*
		rbtree<K, V, C, A, E, bM, bU>::DoCreateNode(const node_type* pNodeSource, node_type* pNodeParent)
	{
		node_type* const pNode = DoCreateNode(pNodeSource->mValue);

		pNode->mpNodeRight  = NULL;
		pNode->mpNodeLeft   = NULL;
		pNode->mpNodeParent = pNodeParent;
		pNode->mColor       = pNodeSource->mColor;

		return pNode;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	typename rbtree<K, V, C, A, E, bM, bU>::node_type*
		rbtree<K, V, C, A, E, bM, bU>::DoCopySubtree(const node_type* pNodeSource, node_type* pNodeDest)
	{
		node_type* const pNewNodeRoot = DoCreateNode(pNodeSource, pNodeDest);

			// Copy the right side of the tree recursively.
			if(pNodeSource->mpNodeRight)
				pNewNodeRoot->mpNodeRight = DoCopySubtree((const node_type*)pNodeSource->mpNodeRight, pNewNodeRoot);

			node_type* pNewNodeLeft;

			for(pNodeSource = (node_type*)pNodeSource->mpNodeLeft, pNodeDest = pNewNodeRoot; 
				pNodeSource;
				pNodeSource = (node_type*)pNodeSource->mpNodeLeft, pNodeDest = pNewNodeLeft)
			{
				pNewNodeLeft = DoCreateNode(pNodeSource, pNodeDest);

				pNodeDest->mpNodeLeft = pNewNodeLeft;

				// Copy the right side of the tree recursively.
				if(pNodeSource->mpNodeRight)
					pNewNodeLeft->mpNodeRight = DoCopySubtree((const node_type*)pNodeSource->mpNodeRight, pNewNodeLeft);
			}
		return pNewNodeRoot;
	}


	template <typename K, typename V, typename C, typename A, typename E, bool bM, bool bU>
	void rbtree<K, V, C, A, E, bM, bU>::DoNukeSubtree(node_type* pNode)
	{
		while(pNode) // Recursively traverse the tree and destroy items as we go.
		{
			DoNukeSubtree((node_type*)pNode->mpNodeRight);

			node_type* const pNodeLeft = (node_type*)pNode->mpNodeLeft;
			DoFreeNode(pNode);
			pNode = pNodeLeft;
		}
	}



	///////////////////////////////////////////////////////////////////////
	// global operators
	///////////////////////////////////////////////////////////////////////

	template <typename K, typename V, typename A, typename C, typename E, bool bM, bool bU>
	inline bool operator==(const rbtree<K, V, C, A, E, bM, bU>& a, const rbtree<K, V, C, A, E, bM, bU>& b)
	{
		return (a.size() == b.size()) && equal(a.begin(), a.end(), b.begin());
	}


	// Note that in operator< we do comparisons based on the tree value_type with operator<() of the
	// value_type instead of the tree's Compare function. For set/multiset, the value_type is T, while
	// for map/multimap the value_type is a pair<Key, T>. operator< for pair can be seen by looking
	// utility.h, but it basically is uses the operator< for pair.first and pair.second. The C++ standard
	// appears to require this behaviour, whether intentionally or not. If anything, a good reason to do
	// this is for consistency. A map and a vector that contain the same items should compare the same.
	template <typename K, typename V, typename A, typename C, typename E, bool bM, bool bU>
	inline bool operator<(const rbtree<K, V, C, A, E, bM, bU>& a, const rbtree<K, V, C, A, E, bM, bU>& b)
	{
		return lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
	}


	template <typename K, typename V, typename A, typename C, typename E, bool bM, bool bU>
	inline bool operator!=(const rbtree<K, V, C, A, E, bM, bU>& a, const rbtree<K, V, C, A, E, bM, bU>& b)
	{
		return !(a == b);
	}


	template <typename K, typename V, typename A, typename C, typename E, bool bM, bool bU>
	inline bool operator>(const rbtree<K, V, C, A, E, bM, bU>& a, const rbtree<K, V, C, A, E, bM, bU>& b)
	{
		return b < a;
	}


	template <typename K, typename V, typename A, typename C, typename E, bool bM, bool bU>
	inline bool operator<=(const rbtree<K, V, C, A, E, bM, bU>& a, const rbtree<K, V, C, A, E, bM, bU>& b)
	{
		return !(b < a);
	}


	template <typename K, typename V, typename A, typename C, typename E, bool bM, bool bU>
	inline bool operator>=(const rbtree<K, V, C, A, E, bM, bU>& a, const rbtree<K, V, C, A, E, bM, bU>& b)
	{
		return !(a < b);
	}


	template <typename K, typename V, typename A, typename C, typename E, bool bM, bool bU>
	inline void swap(rbtree<K, V, C, A, E, bM, bU>& a, rbtree<K, V, C, A, E, bM, bU>& b)
	{
		a.swap(b);
	}


///////////////////////////////////////////////////////////////////////////////
// EASTL/functional.h
// Written and maintained by Paul Pedriana - 2005
///////////////////////////////////////////////////////////////////////////////


	///////////////////////////////////////////////////////////////////////
	// Primary C++ functions
	///////////////////////////////////////////////////////////////////////

	template <typename Argument, typename Result>
	struct unary_function
	{
		typedef Argument argument_type;
		typedef Result   result_type;
	};


	template <typename Argument1, typename Argument2, typename Result>
	struct binary_function
	{
		typedef Argument1 first_argument_type;
		typedef Argument2 second_argument_type;
		typedef Result    result_type;
	};


	template <typename T>
	struct plus : public binary_function<T, T, T>
	{
		T operator()(const T& a, const T& b) const
		{ return a + b; }
	};

	template <typename T>
	struct minus : public binary_function<T, T, T>
	{
		T operator()(const T& a, const T& b) const
		{ return a - b; }
	};

	template <typename T>
	struct multiplies : public binary_function<T, T, T>
	{
		T operator()(const T& a, const T& b) const
		{ return a * b; }
	};

	template <typename T>
	struct divides : public binary_function<T, T, T>
	{
		T operator()(const T& a, const T& b) const
		{ return a / b; }
	};

	template <typename T>
	struct modulus : public binary_function<T, T, T>
	{
		T operator()(const T& a, const T& b) const
		{ return a % b; }
	};

	template <typename T>
	struct negate : public unary_function<T, T>
	{
		T operator()(const T& a) const
		{ return -a; }
	};

	template <typename T>
	struct equal_to : public binary_function<T, T, bool>
	{
		bool operator()(const T& a, const T& b) const
		{ return a == b; }
	};

	template <typename T, typename Compare>
	bool validate_equal_to(const T& a, const T& b, Compare compare)
	{
		return compare(a, b) == compare(b, a);
	}

	template <typename T>
	struct not_equal_to : public binary_function<T, T, bool>
	{
		bool operator()(const T& a, const T& b) const
		{ return a != b; }
	};

	template <typename T, typename Compare>
	bool validate_not_equal_to(const T& a, const T& b, Compare compare)
	{
		return compare(a, b) == compare(b, a); // We want the not equal comparison results to be equal.
	}

	/// str_equal_to
	///
	/// Compares two 0-terminated string types.
	/// The T types are expected to be iterators or act like iterators.
	///
	/// Example usage:
	///     hash_set<const char*, eastl_hash<const char*>, str_equal_to<const char*> > stringHashSet;
	///
	/// Note:
	/// You couldn't use str_equal_to like this:
	///     bool result = equal("hi", "hi" + 2, "ho", str_equal_to<const char*>());
	/// This is because equal tests an array of something, with each element by
	/// the comparison function. But str_equal_to tests an array of something itself.
	///
	template <typename T>
	struct str_equal_to : public binary_function<T, T, bool>
	{
		bool operator()(T a, T b) const
		{
			while(*a && (*a == *b))
			{
				++a;
				++b;
			}
			return (*a == *b);
		}
	};

	template <typename T>
	struct greater : public binary_function<T, T, bool>
	{
		bool operator()(const T& a, const T& b) const
		{ return a > b; }
	};

	template <typename T, typename Compare>
	bool validate_greater(const T& a, const T& b, Compare compare)
	{
		return !compare(a, b) || !compare(b, a); // If (a > b), then !(b > a)
	}

	template <typename T>
	struct less : public binary_function<T, T, bool>
	{
		bool operator()(const T& a, const T& b) const
		{ return a < b; }
	};

	template <typename T, typename Compare>
	bool validate_less(const T& a, const T& b, Compare compare)
	{
		return !compare(a, b) || !compare(b, a); // If (a < b), then !(b < a)
	}

	template <typename T>
	struct greater_equal : public binary_function<T, T, bool>
	{
		bool operator()(const T& a, const T& b) const
		{ return a >= b; }
	};

	template <typename T, typename Compare>
	bool validate_greater_equal(const T& a, const T& b, Compare compare)
	{
		return !compare(a, b) || !compare(b, a); // If (a >= b), then !(b >= a)
	}

	template <typename T>
	struct less_equal : public binary_function<T, T, bool>
	{
		bool operator()(const T& a, const T& b) const
		{ return a <= b; }
	};

	template <typename T, typename Compare>
	bool validate_less_equal(const T& a, const T& b, Compare compare)
	{
		return !compare(a, b) || !compare(b, a); // If (a <= b), then !(b <= a)
	}

	template <typename T>
	struct logical_and : public binary_function<T, T, bool>
	{
		bool operator()(const T& a, const T& b) const
		{ return a && b; }
	};

	template <typename T>
	struct logical_or : public binary_function<T, T, bool>
	{
		bool operator()(const T& a, const T& b) const
		{ return a || b; }
	};

	template <typename T>
	struct logical_not : public unary_function<T, bool>
	{
		bool operator()(const T& a) const
		{ return !a; }
	};



	///////////////////////////////////////////////////////////////////////
	// Dual type functions
	///////////////////////////////////////////////////////////////////////

	template <typename T, typename U>
	struct equal_to_2 : public binary_function<T, U, bool>
	{
		bool operator()(const T& a, const U& b) const
		{ return a == b; }
	};

	template <typename T, typename U>
	struct not_equal_to_2 : public binary_function<T, U, bool>
	{
		bool operator()(const T& a, const U& b) const
		{ return a != b; }
	};

	template <typename T, typename U>
	struct less_2 : public binary_function<T, U, bool>
	{
		bool operator()(const T& a, const U& b) const
		{ return a < b; }
	};




	/// unary_negate
	///
	template <typename Predicate>
	class unary_negate : public unary_function<typename Predicate::argument_type, bool>
	{
	protected:
		Predicate mPredicate;
	public:
		explicit unary_negate(const Predicate& a)
			: mPredicate(a) {}
		bool operator()(const typename Predicate::argument_type& a) const
		{ return !mPredicate(a); }
	};

	template <typename Predicate>
	inline unary_negate<Predicate> not1(const Predicate& predicate)
	{ return unary_negate<Predicate>(predicate); }



	/// binary_negate
	///
	template <typename Predicate>
	class binary_negate : public binary_function<typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool>
	{
	protected:
		Predicate mPredicate;
	public:
		explicit binary_negate(const Predicate& a)
			: mPredicate(a) { }
		bool operator()(const typename Predicate::first_argument_type& a, const typename Predicate::second_argument_type& b) const
		{ return !mPredicate(a, b); }
	};

	template <typename Predicate>
	inline binary_negate<Predicate> not2(const Predicate& predicate)
	{ return binary_negate<Predicate>(predicate); }




	///////////////////////////////////////////////////////////////////////
	// bind
	///////////////////////////////////////////////////////////////////////

	/// bind1st
	///
	template <typename Operation>
	class binder1st : public unary_function<typename Operation::second_argument_type, typename Operation::result_type>
	{
	protected:
		typename Operation::first_argument_type value;
		Operation op;

	public:
		binder1st(const Operation& x, const typename Operation::first_argument_type& y)
			: value(y), op(x) { }

		typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const
		{ return op(value, x); }

		typename Operation::result_type operator()(typename Operation::second_argument_type& x) const
		{ return op(value, x); }
	};


	template <typename Operation, typename T>
	inline binder1st<Operation> bind1st(const Operation& op, const T& x)
	{
		typedef typename Operation::first_argument_type value;
		return binder1st<Operation>(op, value(x));
	}


	/// bind2nd
	///
	template <typename Operation>
	class binder2nd : public unary_function<typename Operation::first_argument_type, typename Operation::result_type>
	{
	protected:
		Operation op;
		typename Operation::second_argument_type value;

	public:
		binder2nd(const Operation& x, const typename Operation::second_argument_type& y)
			: op(x), value(y) { }

		typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const
		{ return op(x, value); }

		typename Operation::result_type operator()(typename Operation::first_argument_type& x) const
		{ return op(x, value); }
	};


	template <typename Operation, typename T>
	inline binder2nd<Operation> bind2nd(const Operation& op, const T& x)
	{
		typedef typename Operation::second_argument_type value;
		return binder2nd<Operation>(op, value(x));
	}




	///////////////////////////////////////////////////////////////////////
	// pointer_to_unary_function
	///////////////////////////////////////////////////////////////////////

	/// pointer_to_unary_function
	///
	/// This is an adapter template which converts a pointer to a standalone
	/// function to a function object. This allows standalone functions to 
	/// work in many cases where the system requires a function object.
	///
	/// Example usage:
	///     ptrdiff_t Rand(ptrdiff_t n) { return rand() % n; } // Note: The C rand function is poor and slow.
	///     pointer_to_unary_function<ptrdiff_t, ptrdiff_t> randInstance(Rand);
	///     random_shuffle(pArrayBegin, pArrayEnd, randInstance);
	///
	template <typename Arg, typename Result>
	class pointer_to_unary_function : public unary_function<Arg, Result>
	{
	protected:
		Result (*mpFunction)(Arg);

	public:
		pointer_to_unary_function()
		{ }

		explicit pointer_to_unary_function(Result (*pFunction)(Arg))
			: mpFunction(pFunction) { }

		Result operator()(Arg x) const
		{ return mpFunction(x); } 
	};


	/// ptr_fun
	///
	/// This ptr_fun is simply shorthand for usage of pointer_to_unary_function.
	///
	/// Example usage (actually, you don't need to use ptr_fun here, but it works anyway):
	///    int factorial(int x) { return (x > 1) ? (x * factorial(x - 1)) : x; }
	///    transform(pIntArrayBegin, pIntArrayEnd, pIntArrayBegin, ptr_fun(factorial));
	///
	template <typename Arg, typename Result>
	inline pointer_to_unary_function<Arg, Result> ptr_fun(Result (*pFunction)(Arg))
	{ return pointer_to_unary_function<Arg, Result>(pFunction); }





	///////////////////////////////////////////////////////////////////////
	// pointer_to_binary_function
	///////////////////////////////////////////////////////////////////////

	/// pointer_to_binary_function
	///
	/// This is an adapter template which converts a pointer to a standalone
	/// function to a function object. This allows standalone functions to 
	/// work in many cases where the system requires a function object.
	///
	template <typename Arg1, typename Arg2, typename Result>
	class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
	{
	protected:
		Result (*mpFunction)(Arg1, Arg2);

	public:
		pointer_to_binary_function()
		{ }

		explicit pointer_to_binary_function(Result (*pFunction)(Arg1, Arg2))
			: mpFunction(pFunction) {}

		Result operator()(Arg1 x, Arg2 y) const
		{ return mpFunction(x, y); }
	};


	/// This ptr_fun is simply shorthand for usage of pointer_to_binary_function.
	///
	/// Example usage (actually, you don't need to use ptr_fun here, but it works anyway):
	///    int multiply(int x, int y) { return x * y; }
	///    transform(pIntArray1Begin, pIntArray1End, pIntArray2Begin, pIntArray1Begin, ptr_fun(multiply));
	///
	template <typename Arg1, typename Arg2, typename Result>
	inline pointer_to_binary_function<Arg1, Arg2, Result> ptr_fun(Result (*pFunction)(Arg1, Arg2))
	{ return pointer_to_binary_function<Arg1, Arg2, Result>(pFunction); }






	///////////////////////////////////////////////////////////////////////
	// mem_fun
	// mem_fun1
	//
	// Note that mem_fun calls member functions via *pointers* to classes 
	// and not instances of classes. mem_fun_ref is for calling functions
	// via instances of classes or references to classes.
	//
	///////////////////////////////////////////////////////////////////////

	/// mem_fun_t
	///
	/// Member function with no arguments.
	///
	template <typename Result, typename T> 
	class mem_fun_t : public unary_function<T*, Result>
	{
	public:
		typedef Result (T::*MemberFunction)();

		MI_INLINE explicit mem_fun_t(MemberFunction pMemberFunction)
			: mpMemberFunction(pMemberFunction)
		{
			// Empty
		}

		MI_INLINE Result operator()(T* pT) const
		{
			return (pT->*mpMemberFunction)();
		}

	protected:
		MemberFunction mpMemberFunction;
	};


	/// mem_fun1_t
	///
	/// Member function with one argument.
	///
	template <typename Result, typename T, typename Argument>
	class mem_fun1_t : public binary_function<T*, Argument, Result>
	{
	public:
		typedef Result (T::*MemberFunction)(Argument);

		MI_INLINE explicit mem_fun1_t(MemberFunction pMemberFunction)
			: mpMemberFunction(pMemberFunction)
		{
			// Empty
		}

		MI_INLINE Result operator()(T* pT, Argument arg) const
		{
			return (pT->*mpMemberFunction)(arg);
		}

	protected:
		MemberFunction mpMemberFunction;
	};


	/// const_mem_fun_t
	///
	/// Const member function with no arguments.
	/// Note that we inherit from unary_function<const T*, Result>
	/// instead of what the C++ standard specifies: unary_function<T*, Result>.
	/// The C++ standard is in error and this has been recognized by the defect group.
	///
	template <typename Result, typename T>
	class const_mem_fun_t : public unary_function<const T*, Result>
	{
	public:
		typedef Result (T::*MemberFunction)() const;

		MI_INLINE explicit const_mem_fun_t(MemberFunction pMemberFunction)
			: mpMemberFunction(pMemberFunction)
		{
			// Empty
		}

		MI_INLINE Result operator()(const T* pT) const
		{
			return (pT->*mpMemberFunction)();
		}

	protected:
		MemberFunction mpMemberFunction;
	};


	/// const_mem_fun1_t
	///
	/// Const member function with one argument.
	/// Note that we inherit from unary_function<const T*, Result>
	/// instead of what the C++ standard specifies: unary_function<T*, Result>.
	/// The C++ standard is in error and this has been recognized by the defect group.
	///
	template <typename Result, typename T, typename Argument>
	class const_mem_fun1_t : public binary_function<const T*, Argument, Result>
	{
	public:
		typedef Result (T::*MemberFunction)(Argument) const;

		MI_INLINE explicit const_mem_fun1_t(MemberFunction pMemberFunction)
			: mpMemberFunction(pMemberFunction)
		{
			// Empty
		}

		MI_INLINE Result operator()(const T* pT, Argument arg) const
		{
			return (pT->*mpMemberFunction)(arg);
		}

	protected:
		MemberFunction mpMemberFunction;
	};


	/// mem_fun
	///
	/// This is the high level interface to the mem_fun_t family.
	///
	/// Example usage:
	///    struct TestClass { void print() { puts("hello"); } }
	///    TestClass* pTestClassArray[3] = { ... };
	///    for_each(pTestClassArray, pTestClassArray + 3, &TestClass::print);
	///
	template <typename Result, typename T>
	MI_INLINE mem_fun_t<Result, T>
		mem_fun(Result (T::*MemberFunction)())
	{
		return mimp::mem_fun_t<Result, T>(MemberFunction);
	}

	template <typename Result, typename T, typename Argument>
	MI_INLINE mem_fun1_t<Result, T, Argument>
		mem_fun(Result (T::*MemberFunction)(Argument))
	{
		return mimp::mem_fun1_t<Result, T, Argument>(MemberFunction);
	}

	template <typename Result, typename T>
	MI_INLINE const_mem_fun_t<Result, T>
		mem_fun(Result (T::*MemberFunction)() const)
	{
		return mimp::const_mem_fun_t<Result, T>(MemberFunction);
	}

	template <typename Result, typename T, typename Argument>
	MI_INLINE const_mem_fun1_t<Result, T, Argument>
		mem_fun(Result (T::*MemberFunction)(Argument) const)
	{
		return mimp::const_mem_fun1_t<Result, T, Argument>(MemberFunction);
	}





	///////////////////////////////////////////////////////////////////////
	// mem_fun_ref
	// mem_fun1_ref
	//
	///////////////////////////////////////////////////////////////////////

	/// mem_fun_ref_t
	///
	template <typename Result, typename T>
	class mem_fun_ref_t : public unary_function<T, Result>
	{
	public:
		typedef Result (T::*MemberFunction)();

		MI_INLINE explicit mem_fun_ref_t(MemberFunction pMemberFunction)
			: mpMemberFunction(pMemberFunction)
		{
			// Empty
		}

		MI_INLINE Result operator()(T& t) const
		{
			return (t.*mpMemberFunction)();
		}

	protected:
		MemberFunction mpMemberFunction;
	};


	/// mem_fun1_ref_t
	///
	template <typename Result, typename T, typename Argument>
	class mem_fun1_ref_t : public binary_function<T, Argument, Result>
	{
	public:
		typedef Result (T::*MemberFunction)(Argument);

		MI_INLINE explicit mem_fun1_ref_t(MemberFunction pMemberFunction)
			: mpMemberFunction(pMemberFunction)
		{
			// Empty
		}

		MI_INLINE Result operator()(T& t, Argument arg) const
		{
			return (t.*mpMemberFunction)(arg);
		}

	protected:
		MemberFunction mpMemberFunction;
	};


	/// const_mem_fun_ref_t
	///
	template <typename Result, typename T>
	class const_mem_fun_ref_t : public unary_function<T, Result>
	{
	public:
		typedef Result (T::*MemberFunction)() const;

		MI_INLINE explicit const_mem_fun_ref_t(MemberFunction pMemberFunction)
			: mpMemberFunction(pMemberFunction)
		{
			// Empty
		}

		MI_INLINE Result operator()(const T& t) const
		{
			return (t.*mpMemberFunction)();
		}

	protected:
		MemberFunction mpMemberFunction;
	};


	/// const_mem_fun1_ref_t
	///
	template <typename Result, typename T, typename Argument>
	class const_mem_fun1_ref_t : public binary_function<T, Argument, Result>
	{
	public:
		typedef Result (T::*MemberFunction)(Argument) const;

		MI_INLINE explicit const_mem_fun1_ref_t(MemberFunction pMemberFunction)
			: mpMemberFunction(pMemberFunction)
		{
			// Empty
		}

		MI_INLINE Result operator()(const T& t, Argument arg) const
		{
			return (t.*mpMemberFunction)(arg);
		}

	protected:
		MemberFunction mpMemberFunction;
	};


	/// mem_fun_ref
	/// Example usage:
	///    struct TestClass { void print() { puts("hello"); } }
	///    TestClass testClassArray[3];
	///    for_each(testClassArray, testClassArray + 3, &TestClass::print);
	///
	template <typename Result, typename T>
	MI_INLINE mem_fun_ref_t<Result, T>
		mem_fun_ref(Result (T::*MemberFunction)())
	{
		return mimp::mem_fun_ref_t<Result, T>(MemberFunction);
	}

	template <typename Result, typename T, typename Argument>
	MI_INLINE mem_fun1_ref_t<Result, T, Argument>
		mem_fun_ref(Result (T::*MemberFunction)(Argument))
	{
		return mimp::mem_fun1_ref_t<Result, T, Argument>(MemberFunction);
	}

	template <typename Result, typename T>
	MI_INLINE const_mem_fun_ref_t<Result, T>
		mem_fun_ref(Result (T::*MemberFunction)() const)
	{
		return mimp::const_mem_fun_ref_t<Result, T>(MemberFunction);
	}

	template <typename Result, typename T, typename Argument>
	MI_INLINE const_mem_fun1_ref_t<Result, T, Argument>
		mem_fun_ref(Result (T::*MemberFunction)(Argument) const)
	{
		return mimp::const_mem_fun1_ref_t<Result, T, Argument>(MemberFunction);
	}




	///////////////////////////////////////////////////////////////////////
	// eastl_hash
	///////////////////////////////////////////////////////////////////////

	template <typename T> struct eastl_hash;

	template <typename T> struct eastl_hash<T*> // Note that we use the pointer as-is and don't divide by sizeof(T*). This is because the table is of a prime size and this division doesn't benefit distribution.
	{ size_t operator()(T* p) const { return size_t(uintptr_t(p)); } };

	template <> struct eastl_hash<bool>
	{ size_t operator()(bool val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<char>
	{ size_t operator()(char val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<signed char>
	{ size_t operator()(signed char val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<unsigned char>
	{ size_t operator()(unsigned char val) const { return static_cast<size_t>(val); } };

#ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type...
	template <> struct eastl_hash<wchar_t>
	{ size_t operator()(wchar_t val) const { return static_cast<size_t>(val); } };
#endif

	template <> struct eastl_hash<signed short>
	{ size_t operator()(short val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<unsigned short>
	{ size_t operator()(unsigned short val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<signed int>
	{ size_t operator()(signed int val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<unsigned int>
	{ size_t operator()(unsigned int val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<signed long>
	{ size_t operator()(signed long val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<unsigned long>
	{ size_t operator()(unsigned long val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<signed long long>
	{ size_t operator()(signed long long val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<unsigned long long>
	{ size_t operator()(unsigned long long val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<float>
	{ size_t operator()(float val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<double>
	{ size_t operator()(double val) const { return static_cast<size_t>(val); } };

	template <> struct eastl_hash<long double>
	{ size_t operator()(long double val) const { return static_cast<size_t>(val); } };


	///////////////////////////////////////////////////////////////////////////
	// string hashes
	//
	// Note that our string hashes here intentionally are slow for long strings.
	// The reasoning for this is so:
	//    - The large majority of hashed strings are only a few bytes long.
	//    - The eastl_hash function is significantly more efficient if it can make this assumption.
	//    - The user is welcome to make a custom eastl_hash for those uncommon cases where
	//      long strings need to be hashed. Indeed, the user can probably make a 
	//      special eastl_hash customized for such strings that's better than what we provide.
	///////////////////////////////////////////////////////////////////////////

	template <> struct eastl_hash<mimp::MiI8*>
	{
		size_t operator()(const mimp::MiI8* p) const
		{
			size_t c, result = 2166136261U;  // FNV1 eastl_hash. Perhaps the best string eastl_hash.
			while((c = (mimp::MiU8)*p++) != 0)  // Using '!=' disables compiler warnings.
				result = (result * 16777619) ^ c;
			return (size_t)result;
		}
	};

	template <> struct eastl_hash<const mimp::MiI8*>
	{
		size_t operator()(const mimp::MiI8* p) const
		{
			size_t c, result = 2166136261U;
			while((c = (mimp::MiU8)*p++) != 0) // cast to unsigned 8 bit.
				result = (result * 16777619) ^ c;
			return (size_t)result;
		}
	};

	template <> struct eastl_hash<mimp::MiI16*>
	{
		size_t operator()(const mimp::MiI16* p) const
		{
			size_t c, result = 2166136261U;
			while((c = (MiU16)*p++) != 0) // cast to unsigned 16 bit.
				result = (result * 16777619) ^ c;
			return (size_t)result;
		}
	};

	template <> struct eastl_hash<const mimp::MiI16*>
	{
		size_t operator()(const mimp::MiI16* p) const
		{
			size_t c, result = 2166136261U;
			while((c = (MiU16)*p++) != 0) // cast to unsigned 16 bit.
				result = (result * 16777619) ^ c;
			return (size_t)result;
		}
	};

	template <> struct eastl_hash<mimp::MiU32*>
	{
		size_t operator()(const mimp::MiU32* p) const
		{
			size_t c, result = 2166136261U;
			while((c = (mimp::MiU32)*p++) != 0) // cast to unsigned 32 bit.
				result = (result * 16777619) ^ c;
			return (size_t)result;
		}
	};

	template <> struct eastl_hash<const mimp::MiU32*>
	{
		size_t operator()(const mimp::MiU32* p) const
		{
			size_t c, result = 2166136261U;
			while((c = (mimp::MiU32)*p++) != 0) // cast to unsigned 32 bit.
				result = (result * 16777619) ^ c;
			return (size_t)result;
		}
	};

	/// string_hash
	///
	/// Defines a generic string eastl_hash for an arbitrary EASTL basic_string container.
	///
	/// Example usage:
	///    mimp::hash_set<MyString, mimp::string_hash<MyString> > hashSet;
	///
	template <typename String>
	struct string_hash
	{
		typedef String                                         string_type;
		typedef typename String::value_type                    value_type;
		typedef typename mimp::add_unsigned<value_type>::type unsigned_value_type;

		size_t operator()(const string_type& s) const
		{
			const unsigned_value_type* p = (const unsigned_value_type*)s.c_str();
			size_t c, result = 2166136261U;
			while((c = *p++) != 0)
				result = (result * 16777619) ^ c;
			return (size_t)result;
		}
	};


} // namespace mimp

#pragma warning(pop)

#endif // include guard

Commits for Divide-Dependencies/physx/APEX_1.4/shared/general/meshimport/include/utils/MiMapSetInternal.h

Diff revisions: vs.
Revision Author Commited Message
105 IonutCava picture IonutCava Tue 16 Apr, 2019 19:55:41 +0000

Forgot to actually add physx