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
|
#ifndef BOOST_LEXICAL_CAST_INCLUDED
#define BOOST_LEXICAL_CAST_INCLUDED
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
// Boost lexical_cast.hpp header -------------------------------------------//
//
// See http://www.boost.org/libs/conversion for documentation.
// See end of this header for rights and permissions.
//
// what: lexical_cast custom keyword cast
// who: contributed by Kevlin Henney,
// enhanced with contributions from Terje Slettebo,
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
// Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2012
#include <boost/config.hpp>
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
#include <climits>
#include <cstddef>
#include <string>
#include <cstring>
#include <cstdio>
#include <typeinfo>
#include <exception>
#include <boost/limits.hpp>
#include <boost/mpl/if.hpp>
#include <boost/throw_exception.hpp>
#include <boost/type_traits/ice.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/static_assert.hpp>
#include <boost/detail/lcast_precision.hpp>
#include <boost/detail/workaround.hpp>
#ifndef BOOST_NO_STD_LOCALE
# include <locale>
#else
# ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
// Getting error at this point means, that your STL library is old/lame/misconfigured.
// If nothing can be done with STL library, define BOOST_LEXICAL_CAST_ASSUME_C_LOCALE,
// but beware: lexical_cast will understand only 'C' locale delimeters and thousands
// separators.
# error "Unable to use <locale> header. Define BOOST_LEXICAL_CAST_ASSUME_C_LOCALE to force "
# error "boost::lexical_cast to use only 'C' locale during conversions."
# endif
#endif
#ifdef BOOST_NO_STRINGSTREAM
#include <strstream>
#else
#include <sstream>
#endif
#ifdef BOOST_NO_TYPEID
#define BOOST_LCAST_THROW_BAD_CAST(S, T) throw_exception(bad_lexical_cast())
#else
#define BOOST_LCAST_THROW_BAD_CAST(Source, Target) \
throw_exception(bad_lexical_cast(typeid(Source), typeid(Target)))
#endif
namespace boost
{
// exception used to indicate runtime lexical_cast failure
class BOOST_SYMBOL_VISIBLE bad_lexical_cast :
// workaround MSVC bug with std::bad_cast when _HAS_EXCEPTIONS == 0
#if defined(BOOST_MSVC) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS
public std::exception
#else
public std::bad_cast
#endif
#if defined(__BORLANDC__) && BOOST_WORKAROUND( __BORLANDC__, < 0x560 )
// under bcc32 5.5.1 bad_cast doesn't derive from exception
, public std::exception
#endif
{
public:
bad_lexical_cast() BOOST_NOEXCEPT :
#ifndef BOOST_NO_TYPEID
source(&typeid(void)), target(&typeid(void))
#else
source(0), target(0) // this breaks getters
#endif
{
}
bad_lexical_cast(
const std::type_info &source_type_arg,
const std::type_info &target_type_arg) BOOST_NOEXCEPT :
source(&source_type_arg), target(&target_type_arg)
{
}
const std::type_info &source_type() const
{
return *source;
}
const std::type_info &target_type() const
{
return *target;
}
#ifndef BOOST_NO_NOEXCEPT
virtual const char *what() const noexcept
#else
virtual const char *what() const throw()
#endif
{
return "bad lexical cast: "
"source type value could not be interpreted as target";
}
#ifndef BOOST_NO_NOEXCEPT
virtual ~bad_lexical_cast() BOOST_NOEXCEPT
#else
virtual ~bad_lexical_cast() throw()
#endif
{}
private:
const std::type_info *source;
const std::type_info *target;
};
namespace detail // widest_char
{
template <typename TargetChar, typename SourceChar>
struct widest_char
{
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
(sizeof(TargetChar) > sizeof(SourceChar))
, TargetChar
, SourceChar >::type type;
};
}
} // namespace boost
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(__SUNPRO_CC) && !defined(__PGIC__)
#include <cmath>
#include <istream>
#if !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY)
#include <array>
#endif
#include <boost/array.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_arithmetic.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/math/special_functions/sign.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/range/iterator_range_core.hpp>
#include <boost/container/container_fwd.hpp>
#ifndef BOOST_NO_CWCHAR
# include <cwchar>
#endif
namespace boost {
namespace detail // widest_char<...> (continuation)
{
struct not_a_character_type{};
template <typename CharT>
struct widest_char<not_a_character_type, CharT >
{
typedef CharT type;
};
template <typename CharT>
struct widest_char< CharT, not_a_character_type >
{
typedef CharT type;
};
template <>
struct widest_char< not_a_character_type, not_a_character_type >
{
typedef char type;
};
}
namespace detail // is_char_or_wchar<...> and stream_char<...> templates
{
// returns true, if T is one of the character types
template <typename T>
struct is_char_or_wchar
{
typedef ::boost::type_traits::ice_or<
::boost::is_same< T, char >::value,
#ifndef BOOST_LCAST_NO_WCHAR_T
::boost::is_same< T, wchar_t >::value,
#endif
#ifndef BOOST_NO_CHAR16_T
::boost::is_same< T, char16_t >::value,
#endif
#ifndef BOOST_NO_CHAR32_T
::boost::is_same< T, char32_t >::value,
#endif
::boost::is_same< T, unsigned char >::value,
::boost::is_same< T, signed char >::value
> result_type;
BOOST_STATIC_CONSTANT(bool, value = (result_type::value) );
};
// selectors for choosing stream character type
// returns one of char, wchar_t, char16_t, char32_t or not_a_character_type types
template <typename Type>
struct stream_char
{
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
is_char_or_wchar<Type >::value,
Type,
boost::detail::not_a_character_type
>::type type;
};
template <>
struct stream_char<unsigned char>
{
typedef char type;
};
template <>
struct stream_char<signed char>
{
typedef char type;
};
template <typename CharT>
struct stream_char<CharT*>
{
typedef BOOST_DEDUCED_TYPENAME stream_char<CharT>::type type;
};
template <typename CharT>
struct stream_char<const CharT*>
{
typedef BOOST_DEDUCED_TYPENAME stream_char<CharT>::type type;
};
template <typename CharT>
struct stream_char<iterator_range<CharT*> >
{
typedef BOOST_DEDUCED_TYPENAME stream_char<CharT*>::type type;
};
template <typename CharT>
struct stream_char<iterator_range<const CharT*> >
{
typedef BOOST_DEDUCED_TYPENAME stream_char<const CharT*>::type type;
};
template <class CharT, class Traits, class Alloc>
struct stream_char< std::basic_string<CharT, Traits, Alloc> >
{
typedef CharT type;
};
template <class CharT, class Traits, class Alloc>
struct stream_char< ::boost::container::basic_string<CharT, Traits, Alloc> >
{
typedef CharT type;
};
template<typename CharT, std::size_t N>
struct stream_char<boost::array<CharT, N> >
{
typedef BOOST_DEDUCED_TYPENAME stream_char<CharT>::type type;
};
template<typename CharT, std::size_t N>
struct stream_char<boost::array<const CharT, N> >
{
typedef BOOST_DEDUCED_TYPENAME stream_char<CharT>::type type;
};
#if !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY)
template <typename CharT, std::size_t N>
struct stream_char<std::array<CharT, N> >
{
typedef BOOST_DEDUCED_TYPENAME stream_char<CharT>::type type;
};
template <typename CharT, std::size_t N>
struct stream_char<std::array<const CharT, N> >
{
typedef BOOST_DEDUCED_TYPENAME stream_char<CharT>::type type;
};
#endif // !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY)
#if !defined(BOOST_LCAST_NO_WCHAR_T) && defined(BOOST_NO_INTRINSIC_WCHAR_T)
template<>
struct stream_char<wchar_t>
{
typedef boost::detail::not_a_character_type type;
};
template<>
struct stream_char<wchar_t*>
{
typedef wchar_t type;
};
template<>
struct stream_char<const wchar_t*>
{
typedef wchar_t type;
};
#endif
}
namespace detail // deduce_char_traits template
{
template<class CharT, class Target, class Source>
struct deduce_char_traits
{
typedef std::char_traits<CharT> type;
};
template<class CharT, class Traits, class Alloc, class Source>
struct deduce_char_traits< CharT
, std::basic_string<CharT,Traits,Alloc>
, Source
>
{
typedef Traits type;
};
template<class CharT, class Target, class Traits, class Alloc>
struct deduce_char_traits< CharT
, Target
, std::basic_string<CharT,Traits,Alloc>
>
{
typedef Traits type;
};
template<class CharT, class Traits, class Alloc, class Source>
struct deduce_char_traits< CharT
, ::boost::container::basic_string<CharT,Traits,Alloc>
, Source
>
{
typedef Traits type;
};
template<class CharT, class Target, class Traits, class Alloc>
struct deduce_char_traits< CharT
, Target
, ::boost::container::basic_string<CharT,Traits,Alloc>
>
{
typedef Traits type;
};
template<class CharT, class Traits, class Alloc1, class Alloc2>
struct deduce_char_traits< CharT
, std::basic_string<CharT,Traits,Alloc1>
, std::basic_string<CharT,Traits,Alloc2>
>
{
typedef Traits type;
};
template<class CharT, class Traits, class Alloc1, class Alloc2>
struct deduce_char_traits< CharT
, ::boost::container::basic_string<CharT,Traits,Alloc1>
, ::boost::container::basic_string<CharT,Traits,Alloc2>
>
{
typedef Traits type;
};
template<class CharT, class Traits, class Alloc1, class Alloc2>
struct deduce_char_traits< CharT
, ::boost::container::basic_string<CharT,Traits,Alloc1>
, ::std::basic_string<CharT,Traits,Alloc2>
>
{
typedef Traits type;
};
template<class CharT, class Traits, class Alloc1, class Alloc2>
struct deduce_char_traits< CharT
, ::std::basic_string<CharT,Traits,Alloc1>
, ::boost::container::basic_string<CharT,Traits,Alloc2>
>
{
typedef Traits type;
};
}
namespace detail // lcast_src_length
{
// Return max. length of string representation of Source;
template< class Source // Source type of lexical_cast.
>
struct lcast_src_length
{
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
// To check coverage, build the test with
// bjam --v2 profile optimization=off
static void check_coverage() {}
};
// Helper for integral types.
// Notes on length calculation:
// Max length for 32bit int with grouping "\1" and thousands_sep ',':
// "-2,1,4,7,4,8,3,6,4,7"
// ^ - is_signed
// ^ - 1 digit not counted by digits10
// ^^^^^^^^^^^^^^^^^^ - digits10 * 2
//
// Constant is_specialized is used instead of constant 1
// to prevent buffer overflow in a rare case when
// <boost/limits.hpp> doesn't add missing specialization for
// numeric_limits<T> for some integral type T.
// When is_specialized is false, the whole expression is 0.
template<class Source>
struct lcast_src_length_integral
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_CONSTANT(std::size_t, value =
std::numeric_limits<Source>::is_signed +
std::numeric_limits<Source>::is_specialized + /* == 1 */
std::numeric_limits<Source>::digits10 * 2
);
#else
BOOST_STATIC_CONSTANT(std::size_t, value = 156);
BOOST_STATIC_ASSERT(sizeof(Source) * CHAR_BIT <= 256);
#endif
};
#define BOOST_LCAST_DEF(T) \
template<> struct lcast_src_length<T> \
: lcast_src_length_integral<T> \
{ static void check_coverage() {} };
BOOST_LCAST_DEF(short)
BOOST_LCAST_DEF(unsigned short)
BOOST_LCAST_DEF(int)
BOOST_LCAST_DEF(unsigned int)
BOOST_LCAST_DEF(long)
BOOST_LCAST_DEF(unsigned long)
#if defined(BOOST_HAS_LONG_LONG)
BOOST_LCAST_DEF(boost::ulong_long_type)
BOOST_LCAST_DEF(boost::long_long_type )
#elif defined(BOOST_HAS_MS_INT64)
BOOST_LCAST_DEF(unsigned __int64)
BOOST_LCAST_DEF( __int64)
#endif
#undef BOOST_LCAST_DEF
#ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
// Helper for floating point types.
// -1.23456789e-123456
// ^ sign
// ^ leading digit
// ^ decimal point
// ^^^^^^^^ lcast_precision<Source>::value
// ^ "e"
// ^ exponent sign
// ^^^^^^ exponent (assumed 6 or less digits)
// sign + leading digit + decimal point + "e" + exponent sign == 5
template<class Source>
struct lcast_src_length_floating
{
BOOST_STATIC_ASSERT(
std::numeric_limits<Source>::max_exponent10 <= 999999L &&
std::numeric_limits<Source>::min_exponent10 >= -999999L
);
BOOST_STATIC_CONSTANT(std::size_t, value =
5 + lcast_precision<Source>::value + 6
);
};
template<>
struct lcast_src_length<float>
: lcast_src_length_floating<float>
{
static void check_coverage() {}
};
template<>
struct lcast_src_length<double>
: lcast_src_length_floating<double>
{
static void check_coverage() {}
};
template<>
struct lcast_src_length<long double>
: lcast_src_length_floating<long double>
{
static void check_coverage() {}
};
#endif // #ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
}
namespace detail // '0', '+' and '-' constants
{
template<typename CharT> struct lcast_char_constants;
template<>
struct lcast_char_constants<char>
{
BOOST_STATIC_CONSTANT(char, zero = '0');
BOOST_STATIC_CONSTANT(char, minus = '-');
BOOST_STATIC_CONSTANT(char, plus = '+');
BOOST_STATIC_CONSTANT(char, lowercase_e = 'e');
BOOST_STATIC_CONSTANT(char, capital_e = 'E');
BOOST_STATIC_CONSTANT(char, c_decimal_separator = '.');
};
#ifndef BOOST_LCAST_NO_WCHAR_T
template<>
struct lcast_char_constants<wchar_t>
{
BOOST_STATIC_CONSTANT(wchar_t, zero = L'0');
BOOST_STATIC_CONSTANT(wchar_t, minus = L'-');
BOOST_STATIC_CONSTANT(wchar_t, plus = L'+');
BOOST_STATIC_CONSTANT(wchar_t, lowercase_e = L'e');
BOOST_STATIC_CONSTANT(wchar_t, capital_e = L'E');
BOOST_STATIC_CONSTANT(wchar_t, c_decimal_separator = L'.');
};
#endif
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
template<>
struct lcast_char_constants<char16_t>
{
BOOST_STATIC_CONSTANT(char16_t, zero = u'0');
BOOST_STATIC_CONSTANT(char16_t, minus = u'-');
BOOST_STATIC_CONSTANT(char16_t, plus = u'+');
BOOST_STATIC_CONSTANT(char16_t, lowercase_e = u'e');
BOOST_STATIC_CONSTANT(char16_t, capital_e = u'E');
BOOST_STATIC_CONSTANT(char16_t, c_decimal_separator = u'.');
};
#endif
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
template<>
struct lcast_char_constants<char32_t>
{
BOOST_STATIC_CONSTANT(char32_t, zero = U'0');
BOOST_STATIC_CONSTANT(char32_t, minus = U'-');
BOOST_STATIC_CONSTANT(char32_t, plus = U'+');
BOOST_STATIC_CONSTANT(char32_t, lowercase_e = U'e');
BOOST_STATIC_CONSTANT(char32_t, capital_e = U'E');
BOOST_STATIC_CONSTANT(char32_t, c_decimal_separator = U'.');
};
#endif
}
namespace detail // lcast_to_unsigned
{
#if (defined _MSC_VER)
# pragma warning( push )
// C4146: unary minus operator applied to unsigned type, result still unsigned
# pragma warning( disable : 4146 )
#elif defined( __BORLANDC__ )
# pragma option push -w-8041
#endif
template<class T>
inline
BOOST_DEDUCED_TYPENAME make_unsigned<T>::type lcast_to_unsigned(T value) BOOST_NOEXCEPT
{
typedef BOOST_DEDUCED_TYPENAME make_unsigned<T>::type result_type;
const result_type uvalue = static_cast<result_type>(value);
return value < 0 ? -uvalue : uvalue;
}
#if (defined _MSC_VER)
# pragma warning( pop )
#elif defined( __BORLANDC__ )
# pragma option pop
#endif
}
namespace detail // lcast_put_unsigned
{
template<class Traits, class T, class CharT>
CharT* lcast_put_unsigned(const T n_param, CharT* finish)
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(!std::numeric_limits<T>::is_signed);
#endif
typedef typename Traits::int_type int_type;
CharT const czero = lcast_char_constants<CharT>::zero;
int_type const zero = Traits::to_int_type(czero);
BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
(sizeof(int_type) > sizeof(T))
, int_type
, T
>::type n = n_param;
#ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
std::locale loc;
if (loc != std::locale::classic()) {
typedef std::numpunct<CharT> numpunct;
numpunct const& np = BOOST_USE_FACET(numpunct, loc);
std::string const grouping = np.grouping();
std::string::size_type const grouping_size = grouping.size();
if ( grouping_size && grouping[0] > 0 )
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
// Check that ulimited group is unreachable:
BOOST_STATIC_ASSERT(std::numeric_limits<T>::digits10 < CHAR_MAX);
#endif
CharT thousands_sep = np.thousands_sep();
std::string::size_type group = 0; // current group number
char last_grp_size = grouping[0];
char left = last_grp_size;
do
{
if(left == 0)
{
++group;
if(group < grouping_size)
{
char const grp_size = grouping[group];
last_grp_size = grp_size <= 0 ? CHAR_MAX : grp_size;
}
left = last_grp_size;
--finish;
Traits::assign(*finish, thousands_sep);
}
--left;
--finish;
int_type const digit = static_cast<int_type>(n % 10U);
Traits::assign(*finish, Traits::to_char_type(zero + digit));
n /= 10;
} while(n);
return finish;
}
}
#endif
{
do
{
--finish;
int_type const digit = static_cast<int_type>(n % 10U);
Traits::assign(*finish, Traits::to_char_type(zero + digit));
n /= 10;
} while(n);
}
return finish;
}
}
namespace detail // lcast_ret_unsigned
{
template<class Traits, class T, class CharT>
inline bool lcast_ret_unsigned(T& value, const CharT* const begin, const CharT* end)
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(!std::numeric_limits<T>::is_signed);
#endif
typedef typename Traits::int_type int_type;
CharT const czero = lcast_char_constants<CharT>::zero;
--end;
value = 0;
if (begin > end || *end < czero || *end >= czero + 10)
return false;
value = *end - czero;
--end;
T multiplier = 1;
bool multiplier_overflowed = false;
#ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
std::locale loc;
if (loc != std::locale::classic()) {
typedef std::numpunct<CharT> numpunct;
numpunct const& np = BOOST_USE_FACET(numpunct, loc);
std::string const& grouping = np.grouping();
std::string::size_type const grouping_size = grouping.size();
/* According to Programming languages - C++
* we MUST check for correct grouping
*/
if (grouping_size && grouping[0] > 0)
{
unsigned char current_grouping = 0;
CharT const thousands_sep = np.thousands_sep();
char remained = grouping[current_grouping] - 1;
bool shall_we_return = true;
for(;end>=begin; --end)
{
if (remained) {
T const multiplier_10 = multiplier * 10;
if (multiplier_10 / 10 != multiplier) multiplier_overflowed = true;
T const dig_value = *end - czero;
T const new_sub_value = multiplier_10 * dig_value;
if (*end < czero || *end >= czero + 10
/* detecting overflow */
|| (dig_value && new_sub_value / dig_value != multiplier_10)
|| static_cast<T>((std::numeric_limits<T>::max)()-new_sub_value) < value
|| (multiplier_overflowed && dig_value)
)
return false;
value += new_sub_value;
multiplier *= 10;
--remained;
} else {
if ( !Traits::eq(*end, thousands_sep) ) //|| begin == end ) return false;
{
/*
* According to Programming languages - C++
* Digit grouping is checked. That is, the positions of discarded
* separators is examined for consistency with
* use_facet<numpunct<charT> >(loc ).grouping()
*
* BUT what if there is no separators at all and grouping()
* is not empty? Well, we have no extraced separators, so we
* won`t check them for consistency. This will allow us to
* work with "C" locale from other locales
*/
shall_we_return = false;
break;
} else {
if ( begin == end ) return false;
if (current_grouping < grouping_size-1 ) ++current_grouping;
remained = grouping[current_grouping];
}
}
}
if (shall_we_return) return true;
}
}
#endif
{
while ( begin <= end )
{
T const multiplier_10 = multiplier * 10;
if (multiplier_10 / 10 != multiplier) multiplier_overflowed = true;
T const dig_value = *end - czero;
T const new_sub_value = multiplier_10 * dig_value;
if (*end < czero || *end >= czero + 10
/* detecting overflow */
|| (dig_value && new_sub_value / dig_value != multiplier_10)
|| static_cast<T>((std::numeric_limits<T>::max)()-new_sub_value) < value
|| (multiplier_overflowed && dig_value)
)
return false;
value += new_sub_value;
multiplier *= 10;
--end;
}
}
return true;
}
}
namespace detail
{
template <class CharT>
bool lc_iequal(const CharT* val, const CharT* lcase, const CharT* ucase, unsigned int len) BOOST_NOEXCEPT {
for( unsigned int i=0; i < len; ++i ) {
if ( val[i] != lcase[i] && val[i] != ucase[i] ) return false;
}
return true;
}
/* Returns true and sets the correct value if found NaN or Inf. */
template <class CharT, class T>
inline bool parse_inf_nan_impl(const CharT* begin, const CharT* end, T& value
, const CharT* lc_NAN, const CharT* lc_nan
, const CharT* lc_INFINITY, const CharT* lc_infinity
, const CharT opening_brace, const CharT closing_brace) BOOST_NOEXCEPT
{
using namespace std;
if (begin == end) return false;
const CharT minus = lcast_char_constants<CharT>::minus;
const CharT plus = lcast_char_constants<CharT>::plus;
const int inifinity_size = 8;
bool has_minus = false;
/* Parsing +/- */
if( *begin == minus)
{
++ begin;
has_minus = true;
}
else if( *begin == plus ) ++begin;
if( end-begin < 3 ) return false;
if( lc_iequal(begin, lc_nan, lc_NAN, 3) )
{
begin += 3;
if (end != begin) /* It is 'nan(...)' or some bad input*/
{
if(end-begin<2) return false; // bad input
-- end;
if( *begin != opening_brace || *end != closing_brace) return false; // bad input
}
if( !has_minus ) value = std::numeric_limits<T>::quiet_NaN();
else value = (boost::math::changesign) (std::numeric_limits<T>::quiet_NaN());
return true;
} else
if (( /* 'INF' or 'inf' */
end-begin==3
&&
lc_iequal(begin, lc_infinity, lc_INFINITY, 3)
)
||
( /* 'INFINITY' or 'infinity' */
end-begin==inifinity_size
&&
lc_iequal(begin, lc_infinity, lc_INFINITY, inifinity_size)
)
)
{
if( !has_minus ) value = std::numeric_limits<T>::infinity();
else value = (boost::math::changesign) (std::numeric_limits<T>::infinity());
return true;
}
return false;
}
template <class CharT, class T>
bool put_inf_nan_impl(CharT* begin, CharT*& end, const T& value
, const CharT* lc_nan
, const CharT* lc_infinity) BOOST_NOEXCEPT
{
using namespace std;
const CharT minus = lcast_char_constants<CharT>::minus;
if ( (boost::math::isnan)(value) )
{
if ( (boost::math::signbit)(value) )
{
*begin = minus;
++ begin;
}
memcpy(begin, lc_nan, 3 * sizeof(CharT));
end = begin + 3;
return true;
} else if ( (boost::math::isinf)(value) )
{
if ( (boost::math::signbit)(value) )
{
*begin = minus;
++ begin;
}
memcpy(begin, lc_infinity, 3 * sizeof(CharT));
end = begin + 3;
return true;
}
return false;
}
#ifndef BOOST_LCAST_NO_WCHAR_T
template <class T>
bool parse_inf_nan(const wchar_t* begin, const wchar_t* end, T& value) BOOST_NOEXCEPT
{
return parse_inf_nan_impl(begin, end, value
, L"NAN", L"nan"
, L"INFINITY", L"infinity"
, L'(', L')');
}
template <class T>
bool put_inf_nan(wchar_t* begin, wchar_t*& end, const T& value) BOOST_NOEXCEPT
{
return put_inf_nan_impl(begin, end, value, L"nan", L"infinity");
}
#endif
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
template <class T>
bool parse_inf_nan(const char16_t* begin, const char16_t* end, T& value) BOOST_NOEXCEPT
{
return parse_inf_nan_impl(begin, end, value
, u"NAN", u"nan"
, u"INFINITY", u"infinity"
, u'(', u')');
}
template <class T>
bool put_inf_nan(char16_t* begin, char16_t*& end, const T& value) BOOST_NOEXCEPT
{
return put_inf_nan_impl(begin, end, value, u"nan", u"infinity");
}
#endif
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
template <class T>
bool parse_inf_nan(const char32_t* begin, const char32_t* end, T& value) BOOST_NOEXCEPT
{
return parse_inf_nan_impl(begin, end, value
, U"NAN", U"nan"
, U"INFINITY", U"infinity"
, U'(', U')');
}
template <class T>
bool put_inf_nan(char32_t* begin, char32_t*& end, const T& value) BOOST_NOEXCEPT
{
return put_inf_nan_impl(begin, end, value, U"nan", U"infinity");
}
#endif
template <class CharT, class T>
bool parse_inf_nan(const CharT* begin, const CharT* end, T& value) BOOST_NOEXCEPT
{
return parse_inf_nan_impl(begin, end, value
, "NAN", "nan"
, "INFINITY", "infinity"
, '(', ')');
}
template <class CharT, class T>
bool put_inf_nan(CharT* begin, CharT*& end, const T& value) BOOST_NOEXCEPT
{
return put_inf_nan_impl(begin, end, value, "nan", "infinity");
}
}
namespace detail // lcast_ret_float
{
template <class T>
struct mantissa_holder_type
{
/* Can not be used with this type */
};
template <>
struct mantissa_holder_type<float>
{
typedef unsigned int type;
};
template <>
struct mantissa_holder_type<double>
{
#if defined(BOOST_HAS_LONG_LONG)
typedef boost::ulong_long_type type;
#elif defined(BOOST_HAS_MS_INT64)
typedef unsigned __int64 type;
#endif
};
template<class Traits, class T, class CharT>
inline bool lcast_ret_float(T& value, const CharT* begin, const CharT* end)
{
#ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
std::locale loc;
typedef std::numpunct<CharT> numpunct;
numpunct const& np = BOOST_USE_FACET(numpunct, loc);
std::string const grouping(
(loc == std::locale::classic())
? std::string()
: np.grouping()
);
std::string::size_type const grouping_size = grouping.size();
CharT const thousands_sep = grouping_size ? np.thousands_sep() : 0;
CharT const decimal_point = np.decimal_point();
bool found_grouping = false;
std::string::size_type last_grouping_pos = grouping_size - 1;
#else
CharT const decimal_point = lcast_char_constants<CharT>::c_decimal_separator;
#endif
CharT const czero = lcast_char_constants<CharT>::zero;
CharT const minus = lcast_char_constants<CharT>::minus;
CharT const plus = lcast_char_constants<CharT>::plus;
CharT const capital_e = lcast_char_constants<CharT>::capital_e;
CharT const lowercase_e = lcast_char_constants<CharT>::lowercase_e;
value = static_cast<T>(0);
if (parse_inf_nan(begin, end, value)) return true;
typedef typename Traits::int_type int_type;
typedef BOOST_DEDUCED_TYPENAME mantissa_holder_type<T>::type mantissa_type;
int_type const zero = Traits::to_int_type(czero);
if (begin == end) return false;
/* Getting the plus/minus sign */
bool has_minus = false;
if (Traits::eq(*begin, minus) ) {
++ begin;
has_minus = true;
if (begin == end) return false;
} else if (Traits::eq(*begin, plus) ) {
++begin;
if (begin == end) return false;
}
bool found_decimal = false;
bool found_number_before_exp = false;
int pow_of_10 = 0;
mantissa_type mantissa=0;
bool is_mantissa_full = false;
char length_since_last_delim = 0;
while ( begin != end )
{
if (found_decimal) {
/* We allow no thousand_separators after decimal point */
mantissa_type tmp_mantissa = mantissa * 10u;
if (Traits::eq(*begin, lowercase_e) || Traits::eq(*begin, capital_e)) break;
if ( *begin < czero || *begin >= czero + 10 ) return false;
if ( is_mantissa_full
|| tmp_mantissa / 10u != mantissa
|| (std::numeric_limits<mantissa_type>::max)()-(*begin - zero) < tmp_mantissa
) {
is_mantissa_full = true;
++ begin;
continue;
}
-- pow_of_10;
mantissa = tmp_mantissa;
mantissa += *begin - zero;
found_number_before_exp = true;
} else {
if (*begin >= czero && *begin < czero + 10) {
/* Checking for mantissa overflow. If overflow will
* occur, them we only increase multiplyer
*/
mantissa_type tmp_mantissa = mantissa * 10u;
if( !is_mantissa_full
&& tmp_mantissa / 10u == mantissa
&& (std::numeric_limits<mantissa_type>::max)()-(*begin - zero) >= tmp_mantissa
)
{
mantissa = tmp_mantissa;
mantissa += *begin - zero;
} else
{
is_mantissa_full = true;
++ pow_of_10;
}
found_number_before_exp = true;
++ length_since_last_delim;
} else if (Traits::eq(*begin, decimal_point) || Traits::eq(*begin, lowercase_e) || Traits::eq(*begin, capital_e)) {
#ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
/* If ( we need to check grouping
* and ( grouping missmatches
* or grouping position is incorrect
* or we are using the grouping position 0 twice
* )
* ) then return error
*/
if( grouping_size && found_grouping
&& (
length_since_last_delim != grouping[0]
|| last_grouping_pos>1
|| (last_grouping_pos==0 && grouping_size>1)
)
) return false;
#endif
if(Traits::eq(*begin, decimal_point)) {
++ begin;
found_decimal = true;
if (!found_number_before_exp && begin==end) return false;
continue;
}else {
if (!found_number_before_exp) return false;
break;
}
}
#ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
else if (grouping_size && Traits::eq(*begin, thousands_sep)){
if(found_grouping)
{
/* It is not he first time, when we find thousands separator,
* so we need to chek, is the distance between two groupings
* equal to grouping[last_grouping_pos] */
if (length_since_last_delim != grouping[last_grouping_pos] )
{
if (!last_grouping_pos) return false;
else
{
-- last_grouping_pos;
if (length_since_last_delim != grouping[last_grouping_pos]) return false;
}
} else
/* We are calling the grouping[0] twice, when grouping size is more than 1 */
if (grouping_size>1u && last_grouping_pos+1<grouping_size) return false;
} else {
/* Delimiter at the begining ',000' */
if (!length_since_last_delim) return false;
found_grouping = true;
if (length_since_last_delim > grouping[last_grouping_pos] ) return false;
}
length_since_last_delim = 0;
++ begin;
/* Delimiter at the end '100,' */
if (begin == end) return false;
continue;
}
#endif
else return false;
}
++begin;
}
// Exponent found
if ( begin != end && (Traits::eq(*begin, lowercase_e) || Traits::eq(*begin, capital_e)) ) {
++ begin;
if ( begin == end ) return false;
bool exp_has_minus = false;
if(Traits::eq(*begin, minus)) {
exp_has_minus = true;
++ begin;
if ( begin == end ) return false;
} else if (Traits::eq(*begin, plus)) {
++ begin;
if ( begin == end ) return false;
}
int exp_pow_of_10 = 0;
while ( begin != end )
{
if ( *begin < czero
|| *begin >= czero + 10
|| exp_pow_of_10 * 10 < exp_pow_of_10) /* Overflows are checked lower more precisely*/
return false;
exp_pow_of_10 *= 10;
exp_pow_of_10 += *begin - zero;
++ begin;
};
if ( exp_pow_of_10 ) {
/* Overflows are checked lower */
if ( exp_has_minus ) {
pow_of_10 -= exp_pow_of_10;
} else {
pow_of_10 += exp_pow_of_10;
}
}
}
/* We need a more accurate algorithm... We can not use current algorithm
* with long doubles (and with doubles if sizeof(double)==sizeof(long double)).
*/
long double result = std::pow(10.0L, pow_of_10) * mantissa;
value = static_cast<T>( has_minus ? (boost::math::changesign)(result) : result);
if ( (boost::math::isinf)(value) || (boost::math::isnan)(value) ) return false;
return true;
}
}
namespace detail // stl_buf_unlocker
{
template< class BufferType, class CharT >
class stl_buf_unlocker: public BufferType{
public:
typedef BufferType base_class;
#ifndef BOOST_NO_USING_TEMPLATE
using base_class::pptr;
using base_class::pbase;
using base_class::setg;
using base_class::setp;
#else
CharT* pptr() const { return base_class::pptr(); }
CharT* pbase() const { return base_class::pbase(); }
void setg(CharT* gbeg, CharT* gnext, CharT* gend){ return base_class::setg(gbeg, gnext, gend); }
void setp(CharT* pbeg, CharT* pend) { return setp(pbeg, pend); }
#endif
};
}
namespace detail
{
struct do_not_construct_out_stream_t{};
}
namespace detail // optimized stream wrapper
{
// String representation of Source has an upper limit.
template< class CharT // a result of widest_char transformation
, class Traits // usually char_traits<CharT>
, bool RequiresStringbuffer
>
class lexical_stream_limited_src
{
#if defined(BOOST_NO_STRINGSTREAM)
typedef std::ostrstream out_stream_t;
typedef stl_buf_unlocker<std::strstreambuf, char> unlocked_but_t;
#elif defined(BOOST_NO_STD_LOCALE)
typedef std::ostringstream out_stream_t;
typedef stl_buf_unlocker<std::stringbuf, char> unlocked_but_t;
#else
typedef std::basic_ostringstream<CharT, Traits> out_stream_t;
typedef stl_buf_unlocker<std::basic_stringbuf<CharT, Traits>, CharT> unlocked_but_t;
#endif
typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c<
RequiresStringbuffer,
out_stream_t,
do_not_construct_out_stream_t
>::type deduced_out_stream_t;
// A string representation of Source is written to [start, finish).
CharT* start;
CharT* finish;
deduced_out_stream_t out_stream;
public:
lexical_stream_limited_src(CharT* sta, CharT* fin)
: start(sta)
, finish(fin)
{}
private:
// Undefined:
lexical_stream_limited_src(lexical_stream_limited_src const&);
void operator=(lexical_stream_limited_src const&);
/************************************ HELPER FUNCTIONS FOR OPERATORS << ( ... ) ********************************/
bool shl_char(CharT ch) BOOST_NOEXCEPT
{
Traits::assign(*start, ch);
finish = start + 1;
return true;
}
#ifndef BOOST_LCAST_NO_WCHAR_T
template <class T>
bool shl_char(T ch)
{
BOOST_STATIC_ASSERT_MSG(( sizeof(T) <= sizeof(CharT)) ,
"boost::lexical_cast does not support narrowing of char types."
"Use boost::locale instead" );
#ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
std::locale loc;
CharT const w = BOOST_USE_FACET(std::ctype<CharT>, loc).widen(ch);
#else
CharT const w = ch;
#endif
Traits::assign(*start, w);
finish = start + 1;
return true;
}
#endif
bool shl_char_array(CharT const* str) BOOST_NOEXCEPT
{
start = const_cast<CharT*>(str);
finish = start + Traits::length(str);
return true;
}
template <class T>
bool shl_char_array(T const* str)
{
BOOST_STATIC_ASSERT_MSG(( sizeof(T) <= sizeof(CharT)),
"boost::lexical_cast does not support narrowing of char types."
"Use boost::locale instead" );
return shl_input_streamable(str);
}
bool shl_char_array_limited(CharT const* str, std::size_t max_size) BOOST_NOEXCEPT
{
start = const_cast<CharT*>(str);
finish = std::find(start, start + max_size, Traits::to_char_type(0));
return true;
}
template<typename InputStreamable>
bool shl_input_streamable(InputStreamable& input)
{
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
// If you have compilation error at this point, than your STL library
// does not support such conversions. Try updating it.
BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
#endif
bool const result = !(out_stream << input).fail();
const unlocked_but_t* const p
= static_cast<unlocked_but_t*>(out_stream.rdbuf()) ;
start = p->pbase();
finish = p->pptr();
return result;
}
template <class T>
inline bool shl_signed(T n)
{
start = lcast_put_unsigned<Traits>(lcast_to_unsigned(n), finish);
if(n < 0)
{
--start;
CharT const minus = lcast_char_constants<CharT>::minus;
Traits::assign(*start, minus);
}
return true;
}
template <class T, class SomeCharT>
bool shl_real_type(const T& val, SomeCharT* begin, SomeCharT*& end)
{
if (put_inf_nan(begin, end, val)) return true;
lcast_set_precision(out_stream, &val);
return shl_input_streamable(val);
}
static bool shl_real_type(float val, char* begin, char*& end)
{ using namespace std;
if (put_inf_nan(begin, end, val)) return true;
const double val_as_double = val;
end = begin +
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
sprintf_s(begin, end-begin,
#else
sprintf(begin,
#endif
"%.*g", static_cast<int>(boost::detail::lcast_get_precision<float>()), val_as_double);
return end > begin;
}
static bool shl_real_type(double val, char* begin, char*& end)
{ using namespace std;
if (put_inf_nan(begin, end, val)) return true;
end = begin +
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
sprintf_s(begin, end-begin,
#else
sprintf(begin,
#endif
"%.*g", static_cast<int>(boost::detail::lcast_get_precision<double>()), val);
return end > begin;
}
#ifndef __MINGW32__
static bool shl_real_type(long double val, char* begin, char*& end)
{ using namespace std;
if (put_inf_nan(begin, end, val)) return true;
end = begin +
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
sprintf_s(begin, end-begin,
#else
sprintf(begin,
#endif
"%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double>()), val );
return end > begin;
}
#endif
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_SWPRINTF) && !defined(__MINGW32__)
static bool shl_real_type(float val, wchar_t* begin, wchar_t*& end)
{ using namespace std;
if (put_inf_nan(begin, end, val)) return true;
const double val_as_double = val;
end = begin + swprintf(begin, end-begin,
L"%.*g",
static_cast<int>(boost::detail::lcast_get_precision<float >()),
val_as_double );
return end > begin;
}
static bool shl_real_type(double val, wchar_t* begin, wchar_t*& end)
{ using namespace std;
if (put_inf_nan(begin, end, val)) return true;
end = begin + swprintf(begin, end-begin,
L"%.*g", static_cast<int>(boost::detail::lcast_get_precision<double >()), val );
return end > begin;
}
static bool shl_real_type(long double val, wchar_t* begin, wchar_t*& end)
{ using namespace std;
if (put_inf_nan(begin, end, val)) return true;
end = begin + swprintf(begin, end-begin,
L"%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double >()), val );
return end > begin;
}
#endif
/************************************ OPERATORS << ( ... ) ********************************/
public:
template<class Alloc>
bool operator<<(std::basic_string<CharT,Traits,Alloc> const& str) BOOST_NOEXCEPT
{
start = const_cast<CharT*>(str.data());
finish = start + str.length();
return true;
}
template<class Alloc>
bool operator<<(::boost::container::basic_string<CharT,Traits,Alloc> const& str) BOOST_NOEXCEPT
{
start = const_cast<CharT*>(str.data());
finish = start + str.length();
return true;
}
bool operator<<(bool value) BOOST_NOEXCEPT
{
CharT const czero = lcast_char_constants<CharT>::zero;
Traits::assign(*start, Traits::to_char_type(czero + value));
finish = start + 1;
return true;
}
bool operator<<(const iterator_range<CharT*>& rng) BOOST_NOEXCEPT
{
start = rng.begin();
finish = rng.end();
return true;
}
bool operator<<(const iterator_range<const CharT*>& rng) BOOST_NOEXCEPT
{
start = const_cast<CharT*>(rng.begin());
finish = const_cast<CharT*>(rng.end());
return true;
}
bool operator<<(const iterator_range<const signed char*>& rng) BOOST_NOEXCEPT
{
return (*this) << iterator_range<char*>(
const_cast<char*>(reinterpret_cast<const char*>(rng.begin())),
const_cast<char*>(reinterpret_cast<const char*>(rng.end()))
);
}
bool operator<<(const iterator_range<const unsigned char*>& rng) BOOST_NOEXCEPT
{
return (*this) << iterator_range<char*>(
const_cast<char*>(reinterpret_cast<const char*>(rng.begin())),
const_cast<char*>(reinterpret_cast<const char*>(rng.end()))
);
}
bool operator<<(const iterator_range<signed char*>& rng) BOOST_NOEXCEPT
{
return (*this) << iterator_range<char*>(
reinterpret_cast<char*>(rng.begin()),
reinterpret_cast<char*>(rng.end())
);
}
bool operator<<(const iterator_range<unsigned char*>& rng) BOOST_NOEXCEPT
{
return (*this) << iterator_range<char*>(
reinterpret_cast<char*>(rng.begin()),
reinterpret_cast<char*>(rng.end())
);
}
bool operator<<(char ch) { return shl_char(ch); }
bool operator<<(unsigned char ch) { return ((*this) << static_cast<char>(ch)); }
bool operator<<(signed char ch) { return ((*this) << static_cast<char>(ch)); }
#if !defined(BOOST_LCAST_NO_WCHAR_T)
bool operator<<(wchar_t const* str) { return shl_char_array(str); }
bool operator<<(wchar_t * str) { return shl_char_array(str); }
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
bool operator<<(wchar_t ch) { return shl_char(ch); }
#endif
#endif
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
bool operator<<(char16_t ch) { return shl_char(ch); }
bool operator<<(char16_t * str) { return shl_char_array(str); }
bool operator<<(char16_t const * str) { return shl_char_array(str); }
#endif
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
bool operator<<(char32_t ch) { return shl_char(ch); }
bool operator<<(char32_t * str) { return shl_char_array(str); }
bool operator<<(char32_t const * str) { return shl_char_array(str); }
#endif
bool operator<<(unsigned char const* ch) { return ((*this) << reinterpret_cast<char const*>(ch)); }
bool operator<<(unsigned char * ch) { return ((*this) << reinterpret_cast<char *>(ch)); }
bool operator<<(signed char const* ch) { return ((*this) << reinterpret_cast<char const*>(ch)); }
bool operator<<(signed char * ch) { return ((*this) << reinterpret_cast<char *>(ch)); }
bool operator<<(char const* str) { return shl_char_array(str); }
bool operator<<(char* str) { return shl_char_array(str); }
bool operator<<(short n) { return shl_signed(n); }
bool operator<<(int n) { return shl_signed(n); }
bool operator<<(long n) { return shl_signed(n); }
bool operator<<(unsigned short n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
bool operator<<(unsigned int n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
bool operator<<(unsigned long n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
#if defined(BOOST_HAS_LONG_LONG)
bool operator<<(boost::ulong_long_type n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
bool operator<<(boost::long_long_type n) { return shl_signed(n); }
#elif defined(BOOST_HAS_MS_INT64)
bool operator<<(unsigned __int64 n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
bool operator<<( __int64 n) { return shl_signed(n); }
#endif
bool operator<<(float val) { return shl_real_type(val, start, finish); }
bool operator<<(double val) { return shl_real_type(val, start, finish); }
bool operator<<(long double val) {
#ifndef __MINGW32__
return shl_real_type(val, start, finish);
#else
return shl_real_type(static_cast<double>(val), start, finish);
#endif
}
template <std::size_t N>
bool operator<<(boost::array<CharT, N> const& input) BOOST_NOEXCEPT
{ return shl_char_array_limited(input.begin(), N); }
template <std::size_t N>
bool operator<<(boost::array<unsigned char, N> const& input) BOOST_NOEXCEPT
{ return ((*this) << reinterpret_cast<boost::array<char, N> const& >(input)); }
template <std::size_t N>
bool operator<<(boost::array<signed char, N> const& input) BOOST_NOEXCEPT
{ return ((*this) << reinterpret_cast<boost::array<char, N> const& >(input)); }
template <std::size_t N>
bool operator<<(boost::array<const CharT, N> const& input) BOOST_NOEXCEPT
{ return shl_char_array_limited(input.begin(), N); }
template <std::size_t N>
bool operator<<(boost::array<const unsigned char, N> const& input) BOOST_NOEXCEPT
{ return ((*this) << reinterpret_cast<boost::array<const char, N> const& >(input)); }
template <std::size_t N>
bool operator<<(boost::array<const signed char, N> const& input) BOOST_NOEXCEPT
{ return ((*this) << reinterpret_cast<boost::array<const char, N> const& >(input)); }
#if !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY)
template <std::size_t N>
bool operator<<(std::array<CharT, N> const& input) BOOST_NOEXCEPT
{ return shl_char_array_limited(input.begin(), N); }
template <std::size_t N>
bool operator<<(std::array<unsigned char, N> const& input) BOOST_NOEXCEPT
{ return ((*this) << reinterpret_cast<boost::array<char, N> const& >(input)); }
template <std::size_t N>
bool operator<<(std::array<signed char, N> const& input) BOOST_NOEXCEPT
{ return ((*this) << reinterpret_cast<boost::array<char, N> const& >(input)); }
template <std::size_t N>
bool operator<<(std::array<const CharT, N> const& input) BOOST_NOEXCEPT
{ return shl_char_array_limited(input.begin(), N); }
template <std::size_t N>
bool operator<<(std::array<const unsigned char, N> const& input) BOOST_NOEXCEPT
{ return ((*this) << reinterpret_cast<boost::array<const char, N> const& >(input)); }
template <std::size_t N>
bool operator<<(std::array<const signed char, N> const& input) BOOST_NOEXCEPT
{ return ((*this) << reinterpret_cast<boost::array<const char, N> const& >(input)); }
#endif // !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY)
template <class InStreamable>
bool operator<<(const InStreamable& input) { return shl_input_streamable(input); }
/************************************ HELPER FUNCTIONS FOR OPERATORS >> ( ... ) ********************************/
private:
template <typename Type>
bool shr_unsigned(Type& output)
{
if (start == finish) return false;
CharT const minus = lcast_char_constants<CharT>::minus;
CharT const plus = lcast_char_constants<CharT>::plus;
bool has_minus = false;
/* We won`t use `start' any more, so no need in decrementing it after */
if ( Traits::eq(minus,*start) )
{
++start;
has_minus = true;
} else if ( Traits::eq( plus, *start ) )
{
++start;
}
bool const succeed = lcast_ret_unsigned<Traits>(output, start, finish);
#if (defined _MSC_VER)
# pragma warning( push )
// C4146: unary minus operator applied to unsigned type, result still unsigned
# pragma warning( disable : 4146 )
#elif defined( __BORLANDC__ )
# pragma option push -w-8041
#endif
if (has_minus) output = static_cast<Type>(-output);
#if (defined _MSC_VER)
# pragma warning( pop )
#elif defined( __BORLANDC__ )
# pragma option pop
#endif
return succeed;
}
template <typename Type>
bool shr_signed(Type& output)
{
if (start == finish) return false;
CharT const minus = lcast_char_constants<CharT>::minus;
CharT const plus = lcast_char_constants<CharT>::plus;
typedef BOOST_DEDUCED_TYPENAME make_unsigned<Type>::type utype;
utype out_tmp =0;
bool has_minus = false;
/* We won`t use `start' any more, so no need in decrementing it after */
if ( Traits::eq(minus,*start) )
{
++start;
has_minus = true;
} else if ( Traits::eq(plus, *start) )
{
++start;
}
bool succeed = lcast_ret_unsigned<Traits>(out_tmp, start, finish);
if (has_minus) {
#if (defined _MSC_VER)
# pragma warning( push )
// C4146: unary minus operator applied to unsigned type, result still unsigned
# pragma warning( disable : 4146 )
#elif defined( __BORLANDC__ )
# pragma option push -w-8041
#endif
utype const comp_val = static_cast<utype>(-(std::numeric_limits<Type>::min)());
succeed = succeed && out_tmp<=comp_val;
output = -out_tmp;
#if (defined _MSC_VER)
# pragma warning( pop )
#elif defined( __BORLANDC__ )
# pragma option pop
#endif
} else {
utype const comp_val = static_cast<utype>((std::numeric_limits<Type>::max)());
succeed = succeed && out_tmp<=comp_val;
output = out_tmp;
}
return succeed;
}
template<typename InputStreamable>
bool shr_using_base_class(InputStreamable& output)
{
#if (defined _MSC_VER)
# pragma warning( push )
// conditional expression is constant
# pragma warning( disable : 4127 )
#endif
if(is_pointer<InputStreamable>::value)
return false;
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
// If you have compilation error at this point, than your STL library
// unsupports such conversions. Try updating it.
BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
#endif
#if defined(BOOST_NO_STRINGSTREAM)
std::istrstream stream(start, finish - start);
#elif defined(BOOST_NO_STD_LOCALE)
std::istringstream stream;
#else
std::basic_istringstream<CharT, Traits> stream;
#endif
static_cast<unlocked_but_t*>(stream.rdbuf())
->setg(start, start, finish);
stream.unsetf(std::ios::skipws);
lcast_set_precision(stream, static_cast<InputStreamable*>(0));
#if (defined _MSC_VER)
# pragma warning( pop )
#endif
return stream >> output &&
stream.get() ==
#if defined(__GNUC__) && (__GNUC__<3) && defined(BOOST_NO_STD_WSTRING)
// GCC 2.9x lacks std::char_traits<>::eof().
// We use BOOST_NO_STD_WSTRING to filter out STLport and libstdc++-v3
// configurations, which do provide std::char_traits<>::eof().
EOF;
#else
Traits::eof();
#endif
}
template<class T>
inline bool shr_xchar(T& output)
{
BOOST_STATIC_ASSERT_MSG(( sizeof(CharT) == sizeof(T) ),
"boost::lexical_cast does not support narrowing of character types."
"Use boost::locale instead" );
bool const ok = (finish - start == 1);
if (ok) {
CharT out;
Traits::assign(out, *start);
output = static_cast<T>(out);
}
return ok;
}
/************************************ OPERATORS >> ( ... ) ********************************/
public:
bool operator>>(unsigned short& output) { return shr_unsigned(output); }
bool operator>>(unsigned int& output) { return shr_unsigned(output); }
bool operator>>(unsigned long int& output) { return shr_unsigned(output); }
bool operator>>(short& output) { return shr_signed(output); }
bool operator>>(int& output) { return shr_signed(output); }
bool operator>>(long int& output) { return shr_signed(output); }
#if defined(BOOST_HAS_LONG_LONG)
bool operator>>(boost::ulong_long_type& output) { return shr_unsigned(output); }
bool operator>>(boost::long_long_type& output) { return shr_signed(output); }
#elif defined(BOOST_HAS_MS_INT64)
bool operator>>(unsigned __int64& output) { return shr_unsigned(output); }
bool operator>>(__int64& output) { return shr_signed(output); }
#endif
bool operator>>(char& output) { return shr_xchar(output); }
bool operator>>(unsigned char& output) { return shr_xchar(output); }
bool operator>>(signed char& output) { return shr_xchar(output); }
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
bool operator>>(wchar_t& output) { return shr_xchar(output); }
#endif
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
bool operator>>(char16_t& output) { return shr_xchar(output); }
#endif
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
bool operator>>(char32_t& output) { return shr_xchar(output); }
#endif
template<class Alloc>
bool operator>>(std::basic_string<CharT,Traits,Alloc>& str) { str.assign(start, finish); return true; }
template<class Alloc>
bool operator>>(::boost::container::basic_string<CharT,Traits,Alloc>& str) { str.assign(start, finish); return true; }
private:
template <std::size_t N, class ArrayT>
bool shr_std_array(ArrayT& output) BOOST_NOEXCEPT
{
using namespace std;
const std::size_t size = finish - start;
if (size > N - 1) { // `-1` because we need to store \0 at the end
return false;
}
memcpy(output.begin(), start, size * sizeof(CharT));
*(output.begin() + size) = Traits::to_char_type(0);
return true;
}
public:
template <std::size_t N>
bool operator>>(boost::array<CharT, N>& output) BOOST_NOEXCEPT
{
return shr_std_array<N>(output);
}
template <std::size_t N>
bool operator>>(boost::array<unsigned char, N>& output)
{
return ((*this) >> reinterpret_cast<boost::array<char, N>& >(output));
}
template <std::size_t N>
bool operator>>(boost::array<signed char, N>& output)
{
return ((*this) >> reinterpret_cast<boost::array<char, N>& >(output));
}
#if !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY)
template <std::size_t N>
bool operator>>(std::array<CharT, N>& output) BOOST_NOEXCEPT
{
return shr_std_array<N>(output);
}
template <std::size_t N>
bool operator>>(std::array<unsigned char, N>& output)
{
return ((*this) >> reinterpret_cast<std::array<char, N>& >(output));
}
template <std::size_t N>
bool operator>>(std::array<signed char, N>& in)
{
return ((*this) >> reinterpret_cast<std::array<char, N>& >(output));
}
#endif // !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY)
/*
* case "-0" || "0" || "+0" : output = false; return true;
* case "1" || "+1": output = true; return true;
* default: return false;
*/
bool operator>>(bool& output) BOOST_NOEXCEPT
{
CharT const zero = lcast_char_constants<CharT>::zero;
CharT const plus = lcast_char_constants<CharT>::plus;
CharT const minus = lcast_char_constants<CharT>::minus;
switch(finish-start)
{
case 1:
output = Traits::eq(start[0], zero+1);
return output || Traits::eq(start[0], zero );
case 2:
if ( Traits::eq( plus, *start) )
{
++start;
output = Traits::eq(start[0], zero +1);
return output || Traits::eq(start[0], zero );
} else
{
output = false;
return Traits::eq( minus, *start)
&& Traits::eq( zero, start[1]);
}
default:
output = false; // Suppress warning about uninitalized variable
return false;
}
}
bool operator>>(float& output) { return lcast_ret_float<Traits>(output,start,finish); }
private:
// Not optimised converter
template <class T>
bool float_types_converter_internal(T& output, int /*tag*/) {
if (parse_inf_nan(start, finish, output)) return true;
bool return_value = shr_using_base_class(output);
/* Some compilers and libraries successfully
* parse 'inf', 'INFINITY', '1.0E', '1.0E-'...
* We are trying to provide a unified behaviour,
* so we just forbid such conversions (as some
* of the most popular compilers/libraries do)
* */
CharT const minus = lcast_char_constants<CharT>::minus;
CharT const plus = lcast_char_constants<CharT>::plus;
CharT const capital_e = lcast_char_constants<CharT>::capital_e;
CharT const lowercase_e = lcast_char_constants<CharT>::lowercase_e;
if ( return_value &&
(
Traits::eq(*(finish-1), lowercase_e) // 1.0e
|| Traits::eq(*(finish-1), capital_e) // 1.0E
|| Traits::eq(*(finish-1), minus) // 1.0e- or 1.0E-
|| Traits::eq(*(finish-1), plus) // 1.0e+ or 1.0E+
)
) return false;
return return_value;
}
// Optimised converter
bool float_types_converter_internal(double& output,char /*tag*/) {
return lcast_ret_float<Traits>(output,start,finish);
}
public:
bool operator>>(double& output)
{
/*
* Some compilers implement long double as double. In that case these types have
* same size, same precision, same max and min values... And it means,
* that current implementation of lcast_ret_float cannot be used for type
* double, because it will give a big precision loss.
* */
boost::mpl::if_c<
#if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)
::boost::type_traits::ice_eq< sizeof(double), sizeof(long double) >::value,
#else
0
#endif
int,
char
>::type tag = 0;
return float_types_converter_internal(output, tag);
}
bool operator>>(long double& output)
{
int tag = 0;
return float_types_converter_internal(output, tag);
}
// Generic istream-based algorithm.
// lcast_streambuf_for_target<InputStreamable>::value is true.
template<typename InputStreamable>
bool operator>>(InputStreamable& output) { return shr_using_base_class(output); }
};
}
namespace detail
{
template<class T>
struct array_to_pointer_decay
{
typedef T type;
};
template<class T, std::size_t N>
struct array_to_pointer_decay<T[N]>
{
typedef const T * type;
};
template<typename T>
struct is_stdstring
{
BOOST_STATIC_CONSTANT(bool, value = false );
};
template<typename CharT, typename Traits, typename Alloc>
struct is_stdstring< std::basic_string<CharT, Traits, Alloc> >
{
BOOST_STATIC_CONSTANT(bool, value = true );
};
template<typename CharT, typename Traits, typename Alloc>
struct is_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc> >
{
BOOST_STATIC_CONSTANT(bool, value = true );
};
template<typename Target, typename Source>
struct is_arithmetic_and_not_xchars
{
BOOST_STATIC_CONSTANT(bool, value =
(
::boost::type_traits::ice_and<
::boost::is_arithmetic<Source>::value,
::boost::is_arithmetic<Target>::value,
::boost::type_traits::ice_not<
detail::is_char_or_wchar<Target>::value
>::value,
::boost::type_traits::ice_not<
detail::is_char_or_wchar<Source>::value
>::value
>::value
)
);
};
/*
* is_xchar_to_xchar<Target, Source>::value is true, when
* Target and Souce are the same char types, or when
* Target and Souce are char types of the same size.
*/
template<typename Target, typename Source>
struct is_xchar_to_xchar
{
BOOST_STATIC_CONSTANT(bool, value =
(
::boost::type_traits::ice_or<
::boost::type_traits::ice_and<
is_same<Source,Target>::value,
is_char_or_wchar<Target>::value
>::value,
::boost::type_traits::ice_and<
::boost::type_traits::ice_eq< sizeof(char),sizeof(Target)>::value,
::boost::type_traits::ice_eq< sizeof(char),sizeof(Source)>::value,
is_char_or_wchar<Target>::value,
is_char_or_wchar<Source>::value
>::value
>::value
)
);
};
// this metafunction evaluates to true, if we have optimized comnversion
// from Float type to Char array.
// Must be in sync with lexical_stream_limited_src<Char, ...>::shl_real_type(...)
template <typename Float, typename Char>
struct is_this_float_conversion_optimized
{
typedef ::boost::type_traits::ice_and<
::boost::is_float<Float>::value,
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_SWPRINTF) && !defined(__MINGW32__)
::boost::type_traits::ice_or<
::boost::type_traits::ice_eq<sizeof(Char), sizeof(char) >::value,
::boost::is_same<Char, wchar_t>::value
>::value
#else
::boost::type_traits::ice_eq<sizeof(Char), sizeof(char) >::value
#endif
> result_type;
BOOST_STATIC_CONSTANT(bool, value = (result_type::value) );
};
template<typename Target, typename Source>
struct is_char_array_to_stdstring
{
BOOST_STATIC_CONSTANT(bool, value = false );
};
template<typename CharT, typename Traits, typename Alloc>
struct is_char_array_to_stdstring< std::basic_string<CharT, Traits, Alloc>, CharT* >
{
BOOST_STATIC_CONSTANT(bool, value = true );
};
template<typename CharT, typename Traits, typename Alloc>
struct is_char_array_to_stdstring< std::basic_string<CharT, Traits, Alloc>, const CharT* >
{
BOOST_STATIC_CONSTANT(bool, value = true );
};
template<typename CharT, typename Traits, typename Alloc>
struct is_char_array_to_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc>, CharT* >
{
BOOST_STATIC_CONSTANT(bool, value = true );
};
template<typename CharT, typename Traits, typename Alloc>
struct is_char_array_to_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc>, const CharT* >
{
BOOST_STATIC_CONSTANT(bool, value = true );
};
#if (defined _MSC_VER)
# pragma warning( push )
# pragma warning( disable : 4701 ) // possible use of ... before initialization
# pragma warning( disable : 4702 ) // unreachable code
# pragma warning( disable : 4267 ) // conversion from 'size_t' to 'unsigned int'
#endif
template<typename Target, typename Source>
struct lexical_cast_do_cast
{
static inline Target lexical_cast_impl(const Source& arg)
{
typedef BOOST_DEDUCED_TYPENAME detail::array_to_pointer_decay<Source>::type src;
typedef BOOST_DEDUCED_TYPENAME ::boost::remove_cv<src>::type no_cv_src;
typedef BOOST_DEDUCED_TYPENAME detail::stream_char<Target>::type target_char_t;
typedef BOOST_DEDUCED_TYPENAME detail::stream_char<no_cv_src>::type src_char_type;
typedef BOOST_DEDUCED_TYPENAME detail::widest_char<
target_char_t, src_char_type
>::type char_type;
#if !defined(BOOST_NO_CHAR16_T) && defined(BOOST_NO_UNICODE_LITERALS)
BOOST_STATIC_ASSERT_MSG(( !::boost::is_same<char16_t, src_char_type>::value
&& !::boost::is_same<char16_t, target_char_t>::value),
"Your compiler does not have full support for char16_t" );
#endif
#if !defined(BOOST_NO_CHAR32_T) && defined(BOOST_NO_UNICODE_LITERALS)
BOOST_STATIC_ASSERT_MSG(( !::boost::is_same<char32_t, src_char_type>::value
&& !::boost::is_same<char32_t, target_char_t>::value),
"Your compiler does not have full support for char32_t" );
#endif
typedef BOOST_DEDUCED_TYPENAME ::boost::detail::deduce_char_traits<
char_type, Target, no_cv_src
>::type traits;
typedef ::boost::type_traits::ice_and<
::boost::detail::is_char_or_wchar<src_char_type>::value, // source is lexical type
::boost::detail::is_char_or_wchar<target_char_t>::value, // target is a lexical type
::boost::is_same<char, src_char_type>::value, // source is not a wide character based type
::boost::type_traits::ice_ne<sizeof(char), sizeof(target_char_t) >::value // target type is based on wide character
> is_string_widening_required_t;
typedef ::boost::type_traits::ice_or<
::boost::is_integral<no_cv_src>::value,
::boost::detail::is_this_float_conversion_optimized<no_cv_src, char_type >::value,
::boost::detail::is_char_or_wchar<src_char_type >::value
> is_source_input_optimized_t;
// Target type must be default constructible
Target result;
// If we have an optimized conversion for
// Source, we do not need to construct stringbuf.
const bool requires_stringbuf = ::boost::type_traits::ice_or<
is_string_widening_required_t::value,
::boost::type_traits::ice_not< is_source_input_optimized_t::value >::value
>::value;
typedef detail::lexical_stream_limited_src<char_type, traits, requires_stringbuf > interpreter_type;
typedef detail::lcast_src_length<no_cv_src> lcast_src_length;
std::size_t const src_len = lcast_src_length::value;
char_type buf[src_len + 1];
lcast_src_length::check_coverage();
interpreter_type interpreter(buf, buf + src_len);
// Disabling ADL, by directly specifying operators.
if(!(interpreter.operator <<(arg) && interpreter.operator >>(result)))
BOOST_LCAST_THROW_BAD_CAST(Source, Target);
return result;
}
};
#if (defined _MSC_VER)
# pragma warning( pop )
#endif
template <typename Source>
struct lexical_cast_copy
{
static inline const Source& lexical_cast_impl(const Source &arg) BOOST_NOEXCEPT
{
return arg;
}
};
template <class Source, class Target >
struct detect_precision_loss
{
typedef boost::numeric::Trunc<Source> Rounder;
typedef Source source_type ;
typedef BOOST_DEDUCED_TYPENAME mpl::if_<
::boost::is_arithmetic<Source>, Source, Source const&
>::type argument_type ;
static source_type nearbyint ( argument_type s )
{
const source_type orig_div_round = s / Rounder::nearbyint(s);
const source_type eps = std::numeric_limits<source_type>::epsilon();
if ((orig_div_round > 1 ? orig_div_round - 1 : 1 - orig_div_round) > eps)
BOOST_LCAST_THROW_BAD_CAST(Source, Target);
return s ;
}
typedef typename Rounder::round_style round_style;
} ;
template <class Source, class Target >
struct nothrow_overflow_handler
{
void operator() ( boost::numeric::range_check_result r )
{
if (r != boost::numeric::cInRange)
BOOST_LCAST_THROW_BAD_CAST(Source, Target);
}
} ;
template <typename Target, typename Source>
struct lexical_cast_dynamic_num_not_ignoring_minus
{
static inline Target lexical_cast_impl(const Source &arg)
{
return boost::numeric::converter<
Target,
Source,
boost::numeric::conversion_traits<Target,Source>,
nothrow_overflow_handler<Source, Target>,
detect_precision_loss<Source, Target>
>::convert(arg);
}
};
template <typename Target, typename Source>
struct lexical_cast_dynamic_num_ignoring_minus
{
static inline Target lexical_cast_impl(const Source &arg)
{
typedef boost::numeric::converter<
Target,
Source,
boost::numeric::conversion_traits<Target,Source>,
nothrow_overflow_handler<Source, Target>,
detect_precision_loss<Source, Target>
> converter_t;
return (
arg < 0 ? -converter_t::convert(-arg) : converter_t::convert(arg)
);
}
};
/*
* lexical_cast_dynamic_num follows the rules:
* 1) If Source can be converted to Target without precision loss and
* without overflows, then assign Source to Target and return
*
* 2) If Source is less than 0 and Target is an unsigned integer,
* then negate Source, check the requirements of rule 1) and if
* successful, assign static_casted Source to Target and return
*
* 3) Otherwise throw a bad_lexical_cast exception
*
*
* Rule 2) required because boost::lexical_cast has the behavior of
* stringstream, which uses the rules of scanf for conversions. And
* in the C99 standard for unsigned input value minus sign is
* optional, so if a negative number is read, no errors will arise
* and the result will be the two's complement.
*/
template <typename Target, typename Source>
struct lexical_cast_dynamic_num
{
static inline Target lexical_cast_impl(const Source &arg)
{
typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c<
::boost::type_traits::ice_and<
::boost::type_traits::ice_or<
::boost::is_signed<Source>::value,
::boost::is_float<Source>::value
>::value,
::boost::type_traits::ice_not<
::boost::is_same<Source, bool>::value
>::value,
::boost::type_traits::ice_not<
::boost::is_same<Target, bool>::value
>::value,
::boost::is_unsigned<Target>::value
>::value,
lexical_cast_dynamic_num_ignoring_minus<Target, Source>,
lexical_cast_dynamic_num_not_ignoring_minus<Target, Source>
>::type caster_type;
return caster_type::lexical_cast_impl(arg);
}
};
}
template <typename Target, typename Source>
inline Target lexical_cast(const Source &arg)
{
typedef BOOST_DEDUCED_TYPENAME ::boost::detail::array_to_pointer_decay<Source>::type src;
typedef BOOST_DEDUCED_TYPENAME ::boost::type_traits::ice_or<
::boost::detail::is_xchar_to_xchar<Target, src >::value,
::boost::detail::is_char_array_to_stdstring<Target, src >::value,
::boost::type_traits::ice_and<
::boost::is_same<Target, src >::value,
::boost::detail::is_stdstring<Target >::value
>::value
> shall_we_copy_t;
typedef BOOST_DEDUCED_TYPENAME
::boost::detail::is_arithmetic_and_not_xchars<Target, src > shall_we_copy_with_dynamic_check_t;
typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c<
shall_we_copy_t::value,
::boost::detail::lexical_cast_copy<src >,
BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c<
shall_we_copy_with_dynamic_check_t::value,
::boost::detail::lexical_cast_dynamic_num<Target, src >,
::boost::detail::lexical_cast_do_cast<Target, src >
>::type
>::type caster_type;
return caster_type::lexical_cast_impl(arg);
}
template <typename Target>
inline Target lexical_cast(const char* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char*>(chars, chars + count)
);
}
template <typename Target>
inline Target lexical_cast(const unsigned char* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const unsigned char*>(chars, chars + count)
);
}
template <typename Target>
inline Target lexical_cast(const signed char* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const signed char*>(chars, chars + count)
);
}
#ifndef BOOST_LCAST_NO_WCHAR_T
template <typename Target>
inline Target lexical_cast(const wchar_t* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const wchar_t*>(chars, chars + count)
);
}
#endif
#ifndef BOOST_NO_CHAR16_T
template <typename Target>
inline Target lexical_cast(const char16_t* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char16_t*>(chars, chars + count)
);
}
#endif
#ifndef BOOST_NO_CHAR32_T
template <typename Target>
inline Target lexical_cast(const char32_t* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char32_t*>(chars, chars + count)
);
}
#endif
} // namespace boost
#else // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace boost {
namespace detail
{
// selectors for choosing stream character type
template<typename Type>
struct stream_char
{
typedef char type;
};
#ifndef BOOST_LCAST_NO_WCHAR_T
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
template<>
struct stream_char<wchar_t>
{
typedef wchar_t type;
};
#endif
template<>
struct stream_char<wchar_t *>
{
typedef wchar_t type;
};
template<>
struct stream_char<const wchar_t *>
{
typedef wchar_t type;
};
template<>
struct stream_char<std::wstring>
{
typedef wchar_t type;
};
#endif
// stream wrapper for handling lexical conversions
template<typename Target, typename Source, typename Traits>
class lexical_stream
{
private:
typedef typename widest_char<
typename stream_char<Target>::type,
typename stream_char<Source>::type>::type char_type;
typedef Traits traits_type;
public:
lexical_stream(char_type* = 0, char_type* = 0)
{
stream.unsetf(std::ios::skipws);
lcast_set_precision(stream, static_cast<Source*>(0), static_cast<Target*>(0) );
}
~lexical_stream()
{
#if defined(BOOST_NO_STRINGSTREAM)
stream.freeze(false);
#endif
}
bool operator<<(const Source &input)
{
return !(stream << input).fail();
}
template<typename InputStreamable>
bool operator>>(InputStreamable &output)
{
return !is_pointer<InputStreamable>::value &&
stream >> output &&
stream.get() ==
#if defined(__GNUC__) && (__GNUC__<3) && defined(BOOST_NO_STD_WSTRING)
// GCC 2.9x lacks std::char_traits<>::eof().
// We use BOOST_NO_STD_WSTRING to filter out STLport and libstdc++-v3
// configurations, which do provide std::char_traits<>::eof().
EOF;
#else
traits_type::eof();
#endif
}
bool operator>>(std::string &output)
{
#if defined(BOOST_NO_STRINGSTREAM)
stream << '\0';
#endif
stream.str().swap(output);
return true;
}
#ifndef BOOST_LCAST_NO_WCHAR_T
bool operator>>(std::wstring &output)
{
stream.str().swap(output);
return true;
}
#endif
private:
#if defined(BOOST_NO_STRINGSTREAM)
std::strstream stream;
#elif defined(BOOST_NO_STD_LOCALE)
std::stringstream stream;
#else
std::basic_stringstream<char_type,traits_type> stream;
#endif
};
}
// call-by-value fallback version (deprecated)
template<typename Target, typename Source>
Target lexical_cast(Source arg)
{
typedef typename detail::widest_char<
BOOST_DEDUCED_TYPENAME detail::stream_char<Target>::type
, BOOST_DEDUCED_TYPENAME detail::stream_char<Source>::type
>::type char_type;
typedef std::char_traits<char_type> traits;
detail::lexical_stream<Target, Source, traits> interpreter;
Target result;
if(!(interpreter << arg && interpreter >> result))
BOOST_LCAST_THROW_BAD_CAST(Source, Target);
return result;
}
} // namespace boost
#endif
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2012.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#undef BOOST_LCAST_THROW_BAD_CAST
#undef BOOST_LCAST_NO_WCHAR_T
#endif // BOOST_LEXICAL_CAST_INCLUDED
|