aboutsummaryrefslogtreecommitdiff
path: root/include/experimental/filesystem
blob: 42157ba309bcef269b2d752d2afb29ab8a7df9af (plain) (blame)
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
// -*- C++ -*-
//===--------------------------- filesystem -------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_EXPERIMENTAL_FILESYSTEM
#define _LIBCPP_EXPERIMENTAL_FILESYSTEM
/*
    filesystem synopsis

    namespace std { namespace experimental { namespace filesystem { inline namespace v1 {

    class path;

    void swap(path& lhs, path& rhs) _NOEXCEPT;
    size_t hash_value(const path& p) _NOEXCEPT;

    bool operator==(const path& lhs, const path& rhs) _NOEXCEPT;
    bool operator!=(const path& lhs, const path& rhs) _NOEXCEPT;
    bool operator< (const path& lhs, const path& rhs) _NOEXCEPT;
    bool operator<=(const path& lhs, const path& rhs) _NOEXCEPT;
    bool operator> (const path& lhs, const path& rhs) _NOEXCEPT;
    bool operator>=(const path& lhs, const path& rhs) _NOEXCEPT;

    path operator/ (const path& lhs, const path& rhs);

    template <class charT, class traits>
    basic_ostream<charT, traits>&
    operator<<(basic_ostream<charT, traits>& os, const path& p);

    template <class charT, class traits>
    basic_istream<charT, traits>&
    operator>>(basic_istream<charT, traits>& is, path& p);

    template <class Source>
      path u8path(const Source& source);
    template <class InputIterator>
      path u8path(InputIterator first, InputIterator last);

    class filesystem_error;
    class directory_entry;

    class directory_iterator;

    // enable directory_iterator range-based for statements
    directory_iterator begin(directory_iterator iter) noexcept;
    directory_iterator end(const directory_iterator&) noexcept;

    class recursive_directory_iterator;

    // enable recursive_directory_iterator range-based for statements
    recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
    recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;

    class file_status;

    struct space_info
    {
      uintmax_t capacity;
      uintmax_t free;
      uintmax_t available;
    };

    enum class file_type;
    enum class perms;
    enum class copy_options;
    enum class directory_options;

    typedef chrono::time_point<trivial-clock>  file_time_type;

    // operational functions

    path absolute(const path& p, const path& base=current_path());

    path canonical(const path& p, const path& base = current_path());
    path canonical(const path& p, error_code& ec);
    path canonical(const path& p, const path& base, error_code& ec);

    void copy(const path& from, const path& to);
    void copy(const path& from, const path& to, error_code& ec) _NOEXCEPT;
    void copy(const path& from, const path& to, copy_options options);
    void copy(const path& from, const path& to, copy_options options,
                   error_code& ec) _NOEXCEPT;

    bool copy_file(const path& from, const path& to);
    bool copy_file(const path& from, const path& to, error_code& ec) _NOEXCEPT;
    bool copy_file(const path& from, const path& to, copy_options option);
    bool copy_file(const path& from, const path& to, copy_options option,
                           error_code& ec) _NOEXCEPT;

    void copy_symlink(const path& existing_symlink, const path& new_symlink);
    void copy_symlink(const path& existing_symlink, const path& new_symlink,
                              error_code& ec) _NOEXCEPT;

    bool create_directories(const path& p);
    bool create_directories(const path& p, error_code& ec) _NOEXCEPT;

    bool create_directory(const path& p);
    bool create_directory(const path& p, error_code& ec) _NOEXCEPT;

    bool create_directory(const path& p, const path& attributes);
    bool create_directory(const path& p, const path& attributes,
                                  error_code& ec) _NOEXCEPT;

    void create_directory_symlink(const path& to, const path& new_symlink);
    void create_directory_symlink(const path& to, const path& new_symlink,
                                          error_code& ec) _NOEXCEPT;

    void create_hard_link(const path& to, const path& new_hard_link);
    void create_hard_link(const path& to, const path& new_hard_link,
                                  error_code& ec) _NOEXCEPT;

    void create_symlink(const path& to, const path& new_symlink);
    void create_symlink(const path& to, const path& new_symlink,
                                error_code& ec) _NOEXCEPT;

    path current_path();
    path current_path(error_code& ec);
    void current_path(const path& p);
    void current_path(const path& p, error_code& ec) _NOEXCEPT;

    bool exists(file_status s) _NOEXCEPT;
    bool exists(const path& p);
    bool exists(const path& p, error_code& ec) _NOEXCEPT;

    bool equivalent(const path& p1, const path& p2);
    bool equivalent(const path& p1, const path& p2, error_code& ec) _NOEXCEPT;

    uintmax_t    file_size(const path& p);
    uintmax_t    file_size(const path& p, error_code& ec) _NOEXCEPT;

    uintmax_t    hard_link_count(const path& p);
    uintmax_t    hard_link_count(const path& p, error_code& ec) _NOEXCEPT;

    bool is_block_file(file_status s) _NOEXCEPT;
    bool is_block_file(const path& p);
    bool is_block_file(const path& p, error_code& ec) _NOEXCEPT;

    bool is_character_file(file_status s) _NOEXCEPT;
    bool is_character_file(const path& p);
    bool is_character_file(const path& p, error_code& ec) _NOEXCEPT;

    bool is_directory(file_status s) _NOEXCEPT;
    bool is_directory(const path& p);
    bool is_directory(const path& p, error_code& ec) _NOEXCEPT;

    bool is_empty(const path& p);
    bool is_empty(const path& p, error_code& ec) _NOEXCEPT;

    bool is_fifo(file_status s) _NOEXCEPT;
    bool is_fifo(const path& p);
    bool is_fifo(const path& p, error_code& ec) _NOEXCEPT;

    bool is_other(file_status s) _NOEXCEPT;
    bool is_other(const path& p);
    bool is_other(const path& p, error_code& ec) _NOEXCEPT;

    bool is_regular_file(file_status s) _NOEXCEPT;
    bool is_regular_file(const path& p);
    bool is_regular_file(const path& p, error_code& ec) _NOEXCEPT;

    bool is_socket(file_status s) _NOEXCEPT;
    bool is_socket(const path& p);
    bool is_socket(const path& p, error_code& ec) _NOEXCEPT;

    bool is_symlink(file_status s) _NOEXCEPT;
    bool is_symlink(const path& p);
    bool is_symlink(const path& p, error_code& ec) _NOEXCEPT;

    file_time_type  last_write_time(const path& p);
    file_time_type  last_write_time(const path& p, error_code& ec) _NOEXCEPT;
    void last_write_time(const path& p, file_time_type new_time);
    void last_write_time(const path& p, file_time_type new_time,
                                 error_code& ec) _NOEXCEPT;

    void permissions(const path& p, perms prms);
    void permissions(const path& p, perms prms, error_code& ec) _NOEXCEPT;

    path read_symlink(const path& p);
    path read_symlink(const path& p, error_code& ec);

    bool remove(const path& p);
    bool remove(const path& p, error_code& ec) _NOEXCEPT;

    uintmax_t    remove_all(const path& p);
    uintmax_t    remove_all(const path& p, error_code& ec) _NOEXCEPT;

    void rename(const path& from, const path& to);
    void rename(const path& from, const path& to, error_code& ec) _NOEXCEPT;

    void resize_file(const path& p, uintmax_t size);
    void resize_file(const path& p, uintmax_t size, error_code& ec) _NOEXCEPT;

    space_info   space(const path& p);
    space_info   space(const path& p, error_code& ec) _NOEXCEPT;

    file_status  status(const path& p);
    file_status  status(const path& p, error_code& ec) _NOEXCEPT;

    bool status_known(file_status s) _NOEXCEPT;

    file_status  symlink_status(const path& p);
    file_status  symlink_status(const path& p, error_code& ec) _NOEXCEPT;

    path system_complete(const path& p);
    path system_complete(const path& p, error_code& ec);

    path temp_directory_path();
    path temp_directory_path(error_code& ec);

} } } }  // namespaces std::experimental::filesystem::v1

*/

#include <experimental/__config>
#include <cstddef>
#include <chrono>
#include <iterator>
#include <iosfwd>
#include <locale>
#include <memory>
#include <stack>
#include <string>
#include <system_error>
#include <utility>
#include <iomanip> // for quoted
#include <string_view>

#include <__debug>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif

#define __cpp_lib_experimental_filesystem 201406

_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM

typedef chrono::time_point<std::chrono::system_clock>  file_time_type;

struct _LIBCPP_TYPE_VIS space_info
{
  uintmax_t capacity;
  uintmax_t free;
  uintmax_t available;
};

enum class _LIBCPP_ENUM_VIS file_type : signed char
{
    none       = 0,
    not_found  = -1,
    regular    = 1,
    directory  = 2,
    symlink    = 3,
    block      = 4,
    character  = 5,
    fifo       = 6,
    socket     = 7,
    unknown    = 8
};

enum class _LIBCPP_ENUM_VIS perms : unsigned
{
    none         = 0,

    owner_read   = 0400,
    owner_write  = 0200,
    owner_exec   = 0100,
    owner_all    = 0700,

    group_read   = 040,
    group_write  = 020,
    group_exec   = 010,
    group_all    = 070,

    others_read  = 04,
    others_write = 02,
    others_exec  = 01,
    others_all   = 07,

    all          = 0777,

    set_uid      = 04000,
    set_gid      = 02000,
    sticky_bit   = 01000,
    mask         = 07777,
    unknown      = 0xFFFF,

    add_perms        = 0x10000,
    remove_perms     = 0x20000,
    symlink_nofollow = 0x40000
};

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR perms operator&(perms _LHS, perms _RHS)
{ return static_cast<perms>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR perms operator|(perms _LHS, perms _RHS)
{ return static_cast<perms>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR perms operator^(perms _LHS, perms _RHS)
{ return static_cast<perms>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR perms operator~(perms _LHS)
{ return static_cast<perms>(~static_cast<unsigned>(_LHS)); }

_LIBCPP_INLINE_VISIBILITY
inline perms& operator&=(perms& _LHS, perms _RHS)
{ return _LHS = _LHS & _RHS; }

_LIBCPP_INLINE_VISIBILITY
inline perms& operator|=(perms& _LHS, perms _RHS)
{ return _LHS = _LHS | _RHS; }

_LIBCPP_INLINE_VISIBILITY
inline perms& operator^=(perms& _LHS, perms _RHS)
{ return _LHS = _LHS ^ _RHS; }

enum class _LIBCPP_ENUM_VIS copy_options : unsigned short
{
    none               = 0,
    skip_existing      = 1,
    overwrite_existing = 2,
    update_existing    = 4,
    recursive          = 8,
    copy_symlinks      = 16,
    skip_symlinks      = 32,
    directories_only   = 64,
    create_symlinks    = 128,
    create_hard_links  = 256,
    __in_recursive_copy = 512,
};

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR copy_options operator&(copy_options _LHS, copy_options _RHS)
{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) & static_cast<unsigned short>(_RHS)); }

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR copy_options operator|(copy_options _LHS, copy_options _RHS)
{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) | static_cast<unsigned short>(_RHS)); }

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR copy_options operator^(copy_options _LHS, copy_options _RHS)
{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^ static_cast<unsigned short>(_RHS)); }

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR copy_options operator~(copy_options _LHS)
{ return static_cast<copy_options>(~static_cast<unsigned short>(_LHS)); }

_LIBCPP_INLINE_VISIBILITY
inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS)
{ return _LHS = _LHS & _RHS; }

_LIBCPP_INLINE_VISIBILITY
inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS)
{ return _LHS = _LHS | _RHS; }

_LIBCPP_INLINE_VISIBILITY
inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS)
{ return _LHS = _LHS ^ _RHS; }


enum class _LIBCPP_ENUM_VIS directory_options : unsigned char
{
    none                     = 0,
    follow_directory_symlink = 1,
    skip_permission_denied   = 2
};

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR directory_options operator&(directory_options _LHS, directory_options _RHS)
{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) & static_cast<unsigned char>(_RHS)); }

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR directory_options operator|(directory_options _LHS, directory_options _RHS)
{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) | static_cast<unsigned char>(_RHS)); }

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR directory_options operator^(directory_options _LHS, directory_options _RHS)
{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^ static_cast<unsigned char>(_RHS)); }

_LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_CONSTEXPR directory_options operator~(directory_options _LHS)
{ return static_cast<directory_options>(~static_cast<unsigned char>(_LHS)); }

_LIBCPP_INLINE_VISIBILITY
inline directory_options& operator&=(directory_options& _LHS, directory_options _RHS)
{ return _LHS = _LHS & _RHS; }

_LIBCPP_INLINE_VISIBILITY
inline directory_options& operator|=(directory_options& _LHS, directory_options _RHS)
{ return _LHS = _LHS | _RHS; }

_LIBCPP_INLINE_VISIBILITY
inline directory_options& operator^=(directory_options& _LHS, directory_options _RHS)
{ return _LHS = _LHS ^ _RHS; }


class _LIBCPP_TYPE_VIS file_status
{
public:
    // constructors
    _LIBCPP_INLINE_VISIBILITY
    file_status() _NOEXCEPT : file_status(file_type::none) {}
    _LIBCPP_INLINE_VISIBILITY
    explicit file_status(file_type __ft,
                         perms __prms = perms::unknown) _NOEXCEPT
      : __ft_(__ft), __prms_(__prms)
    {}

    file_status(const file_status&) _NOEXCEPT = default;
    file_status(file_status&&) _NOEXCEPT = default;

    _LIBCPP_INLINE_VISIBILITY
    ~file_status() {}

    file_status& operator=(const file_status&) _NOEXCEPT = default;
    file_status& operator=(file_status&&) _NOEXCEPT = default;

    // observers
    _LIBCPP_ALWAYS_INLINE
    file_type type() const _NOEXCEPT {
        return __ft_;
    }

    _LIBCPP_ALWAYS_INLINE
    perms permissions() const _NOEXCEPT {
        return __prms_;
    }

    // modifiers
    _LIBCPP_ALWAYS_INLINE
    void type(file_type __ft) _NOEXCEPT {
        __ft_ = __ft;
    }

    _LIBCPP_ALWAYS_INLINE
    void permissions(perms __p) _NOEXCEPT {
        __prms_ = __p;
    }
private:
    file_type __ft_;
    perms __prms_;
};

class _LIBCPP_TYPE_VIS directory_entry;

template <class _Tp> struct __can_convert_char {
  static const bool value = false;
};
template <class _Tp> struct __can_convert_char<const _Tp>
    : public __can_convert_char<_Tp> {
};
template <> struct __can_convert_char<char> {
    static const bool value = true;
    using __char_type = char;
};
template <> struct __can_convert_char<wchar_t>  {
    static const bool value = true;
    using __char_type = wchar_t;
};
template <> struct __can_convert_char<char16_t> {
    static const bool value = true;
    using __char_type = char16_t;
};
template <> struct __can_convert_char<char32_t> {
    static const bool value = true;
    using __char_type = char32_t;
};

template <class _ECharT>
typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
__is_separator(_ECharT __e) {
    return __e == _ECharT('/');
};

struct _NullSentinal {};

template <class _Tp>
using _Void = void;

template <class _Tp, class = void>
struct __is_pathable_string : public false_type {};

template <class _ECharT, class _Traits, class _Alloc>
struct __is_pathable_string<basic_string<_ECharT, _Traits, _Alloc>,
                            _Void<typename __can_convert_char<_ECharT>::__char_type>>
: public __can_convert_char<_ECharT>
{
    using _Str = basic_string<_ECharT, _Traits, _Alloc>;
    using _Base = __can_convert_char<_ECharT>;
    static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
    static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
    static _ECharT __first_or_null(_Str const& __s) {
        return __s.empty() ? _ECharT{} : __s[0];
    }
};


template <class _ECharT, class _Traits>
struct __is_pathable_string<basic_string_view<_ECharT, _Traits>,
                            _Void<typename __can_convert_char<_ECharT>::__char_type>>
: public __can_convert_char<_ECharT>
{
    using _Str = basic_string_view<_ECharT, _Traits>;
    using _Base = __can_convert_char<_ECharT>;
    static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
    static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
    static _ECharT __first_or_null(_Str const& __s) {
        return __s.empty() ? _ECharT{} : __s[0];
    }
};

template <class _Source,
          class _DS = typename decay<_Source>::type,
          class _UnqualPtrType = typename remove_const<
              typename remove_pointer<_DS>::type>::type,
          bool _IsCharPtr = is_pointer<_DS>::value &&
                            __can_convert_char<_UnqualPtrType>::value
        >
struct __is_pathable_char_array : false_type {};

template <class _Source, class _ECharT, class _UPtr>
struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
        : __can_convert_char<typename remove_const<_ECharT>::type>
{
  using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;

  static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
  static _ECharT const* __range_end(const _ECharT* __b)
  {
      using _Iter = const _ECharT*;
      const _ECharT __sentinal = _ECharT{};
      _Iter __e = __b;
      for (; *__e != __sentinal; ++__e)
          ;
      return __e;
  }

  static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
};

template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value, class = void>
struct __is_pathable_iter : false_type {};

template <class _Iter>
struct __is_pathable_iter<_Iter, true,
        _Void<typename __can_convert_char<typename iterator_traits<_Iter>::value_type>::__char_type>>
        : __can_convert_char<typename iterator_traits<_Iter>::value_type>
{
  using _ECharT = typename iterator_traits<_Iter>::value_type;
  using _Base = __can_convert_char<_ECharT>;

  static _Iter         __range_begin(_Iter __b) { return __b; }
  static _NullSentinal __range_end(_Iter)       { return _NullSentinal{}; }

  static _ECharT __first_or_null(_Iter __b) { return *__b; }
};

template <class _Tp, bool _IsStringT =  __is_pathable_string<_Tp>::value,
                     bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
                     bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value
         >
struct __is_pathable : false_type {
  static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
};

template <class _Tp>
struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};


template <class _Tp>
struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {};


template <class _Tp>
struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};


template <class _ECharT>
struct _PathCVT {
    static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible");

    typedef __narrow_to_utf8<sizeof(_ECharT)*__CHAR_BIT__> _Narrower;

    static void __append_range(string& __dest, _ECharT const* __b, _ECharT const* __e)  {
        _Narrower()(back_inserter(__dest), __b, __e);
    }

    template <class _Iter>
    static void __append_range(string& __dest, _Iter __b, _Iter __e) {
        static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
        if (__b == __e) return;
        basic_string<_ECharT> __tmp(__b, __e);
        _Narrower()(back_inserter(__dest), __tmp.data(),
                    __tmp.data() + __tmp.length());
    }

    template <class _Iter>
    static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
        static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
        const _ECharT __sentinal = _ECharT{};
        if (*__b == __sentinal) return;
        basic_string<_ECharT> __tmp;
        for (; *__b != __sentinal; ++__b)
            __tmp.push_back(*__b);
        _Narrower()(back_inserter(__dest), __tmp.data(),
                    __tmp.data() + __tmp.length());
    }

    template <class _Source>
    static void __append_source(string& __dest, _Source const& __s)
    {
        using _Traits = __is_pathable<_Source>;
        __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
    }
};

template <>
struct _PathCVT<char> {

    template <class _Iter>
    static typename enable_if<
        __is_exactly_input_iterator<_Iter>::value
    >::type __append_range(string& __dest, _Iter __b, _Iter __e) {
        for (; __b != __e; ++__b)
            __dest.push_back(*__b);
    }

    template <class _Iter>
    static typename enable_if<
        __is_forward_iterator<_Iter>::value
    >::type __append_range(string& __dest, _Iter __b, _Iter __e) {
        __dest.__append_forward_unsafe(__b, __e);
    }

    template <class _Iter>
    static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
        const char __sentinal = char{};
        for (; *__b != __sentinal; ++__b)
            __dest.push_back(*__b);
    }

    template <class _Source>
    static void __append_source(string& __dest, _Source const& __s)
    {
        using _Traits = __is_pathable<_Source>;
        __append_range(__dest, _Traits::__range_begin(__s),
                               _Traits::__range_end(__s));
    }
};


class _LIBCPP_TYPE_VIS path
{
    template <class _SourceOrIter, class _Tp = path&>
    using _EnableIfPathable = typename
        enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;

    template <class _Tp>
    using _SourceChar = typename __is_pathable<_Tp>::__char_type;

    template <class _Tp>
    using _SourceCVT = _PathCVT<_SourceChar<_Tp>>;

public:
    typedef char value_type;
    typedef basic_string<value_type> string_type;
    typedef _VSTD::string_view __string_view;
    static _LIBCPP_CONSTEXPR value_type preferred_separator = '/';

    // constructors and destructor
    _LIBCPP_INLINE_VISIBILITY path() _NOEXCEPT {}
    _LIBCPP_INLINE_VISIBILITY path(const path& __p)      : __pn_(__p.__pn_) {}
    _LIBCPP_INLINE_VISIBILITY path(path&& __p) _NOEXCEPT : __pn_(_VSTD::move(__p.__pn_)) {}

    _LIBCPP_INLINE_VISIBILITY
    path(string_type&& __s) _NOEXCEPT : __pn_(_VSTD::move(__s)) {}

    template <
        class _Source,
        class = _EnableIfPathable<_Source, void>
        >
    path(const _Source& __src) {
        _SourceCVT<_Source>::__append_source(__pn_, __src);
    }

    template <class _InputIt>
    path(_InputIt __first, _InputIt __last) {
        typedef typename iterator_traits<_InputIt>::value_type _ItVal;
        _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
    }

    // TODO Implement locale conversions.
    template <class _Source,
              class = _EnableIfPathable<_Source, void>
             >
        path(const _Source& __src, const locale& __loc);
    template <class _InputIt>
        path(_InputIt __first, _InputIt _last, const locale& __loc);

    _LIBCPP_INLINE_VISIBILITY
    ~path() = default;

    // assignments
    _LIBCPP_INLINE_VISIBILITY
    path& operator=(const path& __p) {
        __pn_ = __p.__pn_;
        return *this;
    }

    _LIBCPP_INLINE_VISIBILITY
    path& operator=(path&& __p) _NOEXCEPT {
        __pn_ = _VSTD::move(__p.__pn_);
        return *this;
    }

    template <class = void>
    _LIBCPP_INLINE_VISIBILITY
    path& operator=(string_type&& __s) _NOEXCEPT {
        __pn_ = _VSTD::move(__s);
        return *this;
    }

    _LIBCPP_INLINE_VISIBILITY
    path& assign(string_type&& __s) _NOEXCEPT {
        __pn_ = _VSTD::move(__s);
        return *this;
    }

    template <class _Source>
    _LIBCPP_INLINE_VISIBILITY
    _EnableIfPathable<_Source>
    operator=(const _Source& __src)
    { return this->assign(__src); }


    template <class _Source>
    _EnableIfPathable<_Source>
    assign(const _Source& __src) {
        __pn_.clear();
        _SourceCVT<_Source>::__append_source(__pn_, __src);
        return *this;
    }

    template <class _InputIt>
    path& assign(_InputIt __first, _InputIt __last) {
        typedef typename iterator_traits<_InputIt>::value_type _ItVal;
        __pn_.clear();
        _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
        return *this;
    }

private:
    template <class _ECharT>
    void __append_sep_if_needed(_ECharT __first_or_null) {
        const _ECharT __null_val = {};
        bool __append_sep = !empty()                       &&
                            !__is_separator(__pn_.back())  &&
                            __first_or_null != __null_val  && // non-empty
                            !__is_separator(__first_or_null);
        if (__append_sep)
            __pn_ += preferred_separator;
    }

public:
    // appends
    path& operator/=(const path& __p) {
        _LIBCPP_ASSERT(!__p.has_root_name(),
                      "cannot append to a path with a root name");
        __append_sep_if_needed(__p.empty() ? char{} : __p.__pn_[0]);
        __pn_ += __p.native();
        return *this;
    }

    template <class _Source>
    _LIBCPP_INLINE_VISIBILITY
    _EnableIfPathable<_Source>
    operator/=(const _Source& __src) {
        return this->append(__src);
    }

    template <class _Source>
    _EnableIfPathable<_Source>
    append(const _Source& __src) {
        using _Traits = __is_pathable<_Source>;
        using _CVT = _PathCVT<_SourceChar<_Source>>;
        __append_sep_if_needed(_Traits::__first_or_null(__src));
        _CVT::__append_source(__pn_, __src);
        return *this;
    }

    template <class _InputIt>
    path& append(_InputIt __first, _InputIt __last) {
        typedef typename iterator_traits<_InputIt>::value_type _ItVal;
        static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
        using _CVT = _PathCVT<_ItVal>;
        if (__first != __last) {
            __append_sep_if_needed(*__first);
            _CVT::__append_range(__pn_, __first, __last);
        }
        return *this;
    }

    // concatenation
    _LIBCPP_INLINE_VISIBILITY
    path& operator+=(const path& __x) {
        __pn_ += __x.__pn_;
        return *this;
    }

    _LIBCPP_INLINE_VISIBILITY
    path& operator+=(const string_type& __x) {
        __pn_ += __x;
        return *this;
    }

    _LIBCPP_INLINE_VISIBILITY
    path& operator+=(__string_view __x) {
        __pn_ += __x;
        return *this;
    }

    _LIBCPP_INLINE_VISIBILITY
    path& operator+=(const value_type* __x) {
        __pn_ += __x;
        return *this;
    }

    _LIBCPP_INLINE_VISIBILITY
    path& operator+=(value_type __x) {
        __pn_ += __x;
        return *this;
    }

    template <class _ECharT>
    typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
    operator+=(_ECharT __x)
    {
        basic_string<_ECharT> __tmp;
        __tmp += __x;
        _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
        return *this;
    }

    template <class _Source>
    _EnableIfPathable<_Source>
    operator+=(const _Source& __x) {
       return this->concat(__x);
    }

    template <class _Source>
    _EnableIfPathable<_Source>
    concat(const _Source& __x) {
         _SourceCVT<_Source>::__append_source(__pn_, __x);
        return *this;
    }

    template <class _InputIt>
    path& concat(_InputIt __first, _InputIt __last) {
        typedef typename iterator_traits<_InputIt>::value_type _ItVal;
        _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
        return *this;
    }

    // modifiers
    _LIBCPP_INLINE_VISIBILITY
    void clear() _NOEXCEPT {
        __pn_.clear();
    }

    path& make_preferred() { return *this; }

    _LIBCPP_INLINE_VISIBILITY
    path& remove_filename() {
      if (__pn_.size() == __root_path_raw().size())
        clear();
      else
        __pn_ = __parent_path();
      return *this;
    }

    path& replace_filename(const path& __replacement) {
        remove_filename();
        return (*this /= __replacement);
    }

    path& replace_extension(const path& __replacement = path());

    _LIBCPP_INLINE_VISIBILITY
    void  swap(path& __rhs) _NOEXCEPT {
        __pn_.swap(__rhs.__pn_);
    }

    // native format observers
    _LIBCPP_INLINE_VISIBILITY
    const string_type& native() const _NOEXCEPT {
        return __pn_;
    }

    _LIBCPP_INLINE_VISIBILITY
    const value_type* c_str() const _NOEXCEPT { return __pn_.c_str(); }

    _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_;  }

    template <class _ECharT, class _Traits = char_traits<_ECharT>,
              class _Allocator = allocator<_ECharT> >
    basic_string<_ECharT, _Traits, _Allocator>
    string(const _Allocator& __a = _Allocator()) const {
        using _CVT = __widen_from_utf8<sizeof(_ECharT)*__CHAR_BIT__>;
        using _Str = basic_string<_ECharT, _Traits, _Allocator>;
        _Str __s(__a);
        __s.reserve(__pn_.size());
        _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
        return __s;
    }

    _LIBCPP_INLINE_VISIBILITY std::string    string()    const { return __pn_; }
    _LIBCPP_INLINE_VISIBILITY std::wstring   wstring()   const { return string<wchar_t>(); }
    _LIBCPP_INLINE_VISIBILITY std::string    u8string()  const { return __pn_; }
    _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { return string<char16_t>(); }
    _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { return string<char32_t>(); }

    // generic format observers
    template <class _ECharT, class _Traits = char_traits<_ECharT>,
              class _Allocator = allocator<_ECharT>
    >
    basic_string<_ECharT, _Traits, _Allocator>
    generic_string(const _Allocator& __a = _Allocator()) const {
        return string<_ECharT, _Traits, _Allocator>(__a);
    }

    std::string    generic_string()    const { return __pn_; }
    std::wstring   generic_wstring()   const { return string<wchar_t>(); }
    std::string    generic_u8string()  const { return __pn_; }
    std::u16string generic_u16string() const { return string<char16_t>(); }
    std::u32string generic_u32string() const { return string<char32_t>(); }

private:
    int __compare(__string_view) const;
    __string_view __root_name() const;
    __string_view __root_directory() const;
    __string_view __root_path_raw() const;
    __string_view __relative_path() const;
    __string_view __parent_path() const;
    __string_view __filename() const;
    __string_view __stem() const;
    __string_view __extension() const;

public:
    // compare
    _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const _NOEXCEPT { return __compare(__p.__pn_);}
    _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); }
    _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); }
    _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const  { return __compare(__s); }

    // decomposition
    _LIBCPP_INLINE_VISIBILITY path root_name()      const { return  string_type(__root_name()); }
    _LIBCPP_INLINE_VISIBILITY path root_directory() const { return  string_type(__root_directory()); }
    _LIBCPP_INLINE_VISIBILITY path root_path()      const { return root_name().append(string_type(__root_directory())); }
    _LIBCPP_INLINE_VISIBILITY path relative_path()  const { return string_type(__relative_path()); }
    _LIBCPP_INLINE_VISIBILITY path parent_path()    const { return string_type(__parent_path()); }
    _LIBCPP_INLINE_VISIBILITY path filename()       const { return string_type(__filename()); }
    _LIBCPP_INLINE_VISIBILITY path stem()           const { return string_type(__stem());}
    _LIBCPP_INLINE_VISIBILITY path extension()      const { return string_type(__extension()); }

    // query
    _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT { return __pn_.empty(); }

    _LIBCPP_INLINE_VISIBILITY bool has_root_name()      const { return !__root_name().empty(); }
    _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); }
    _LIBCPP_INLINE_VISIBILITY bool has_root_path()      const { return !__root_path_raw().empty(); }
    _LIBCPP_INLINE_VISIBILITY bool has_relative_path()  const { return !__relative_path().empty(); }
    _LIBCPP_INLINE_VISIBILITY bool has_parent_path()    const { return !__parent_path().empty(); }
    _LIBCPP_INLINE_VISIBILITY bool has_filename()       const { return !__filename().empty(); }
    _LIBCPP_INLINE_VISIBILITY bool has_stem()           const { return !__stem().empty(); }
    _LIBCPP_INLINE_VISIBILITY bool has_extension()      const { return !__extension().empty(); }

    _LIBCPP_INLINE_VISIBILITY bool is_absolute()        const { return has_root_directory(); }
    _LIBCPP_INLINE_VISIBILITY bool is_relative()        const { return !is_absolute(); }

    // iterators
    class _LIBCPP_TYPE_VIS iterator;
    typedef iterator const_iterator;

    iterator begin() const;
    iterator end() const;

private:
    inline _LIBCPP_INLINE_VISIBILITY
    path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; }
    string_type __pn_;
};

inline _LIBCPP_ALWAYS_INLINE
void swap(path& __lhs, path& __rhs) _NOEXCEPT {
    __lhs.swap(__rhs);
}

_LIBCPP_FUNC_VIS
size_t hash_value(const path& __p) _NOEXCEPT;

inline _LIBCPP_INLINE_VISIBILITY
bool operator==(const path& __lhs, const path& __rhs) _NOEXCEPT
{ return __lhs.compare(__rhs) == 0; }

inline _LIBCPP_INLINE_VISIBILITY
bool operator!=(const path& __lhs, const path& __rhs) _NOEXCEPT
{ return __lhs.compare(__rhs) != 0; }

inline _LIBCPP_INLINE_VISIBILITY
bool operator<(const path& __lhs, const path& __rhs) _NOEXCEPT
{ return __lhs.compare(__rhs) < 0; }

inline _LIBCPP_INLINE_VISIBILITY
bool operator<=(const path& __lhs, const path& __rhs) _NOEXCEPT
{ return __lhs.compare(__rhs) <= 0; }

inline _LIBCPP_INLINE_VISIBILITY
bool operator>(const path& __lhs, const path& __rhs) _NOEXCEPT
{ return __lhs.compare(__rhs) > 0; }

inline _LIBCPP_INLINE_VISIBILITY
bool operator>=(const path& __lhs, const path& __rhs) _NOEXCEPT
{ return __lhs.compare(__rhs) >= 0; }

inline _LIBCPP_INLINE_VISIBILITY
path operator/(const path& __lhs, const path& __rhs) {
    return path(__lhs) /= __rhs;
}

template <class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<is_same<_CharT, char>::value &&
                   is_same<_Traits, char_traits<char>>::value,
                   basic_ostream<_CharT, _Traits>&
>::type
operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
    __os << std::__quoted(__p.native());
    return __os;
}

template <class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<!is_same<_CharT, char>::value ||
                   !is_same<_Traits, char_traits<char>>::value,
                   basic_ostream<_CharT, _Traits>&
>::type
operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
    __os << std::__quoted(__p.string<_CharT, _Traits>());
    return __os;
}

template <class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
{
    basic_string<_CharT, _Traits> __tmp;
    __is >> __quoted(__tmp);
    __p = __tmp;
    return __is;
}

template <class _Source>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_pathable<_Source>::value, path>::type
u8path(const _Source& __s){
    static_assert(is_same<typename __is_pathable<_Source>::__char_type, char>::value,
        "u8path(Source const&) requires Source have a character type of type 'char'");
    return path(__s);
}

template <class _InputIt>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_pathable<_InputIt>::value, path>::type
u8path(_InputIt __f, _InputIt __l) {
    static_assert(is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
        "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
    return path(__f, __l);
}

class _LIBCPP_TYPE_VIS path::iterator
{
public:
    typedef bidirectional_iterator_tag iterator_category;

    typedef path                       value_type;
    typedef std::ptrdiff_t             difference_type;
    typedef const path*                pointer;
    typedef const path&                reference;

    typedef void __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
public:
    _LIBCPP_INLINE_VISIBILITY
    iterator() : __stashed_elem_(), __path_ptr_(nullptr),
                 __entry_(), __state_(__singular) {}

    iterator(const iterator&) = default;
    ~iterator() = default;

    iterator& operator=(const iterator&) = default;

    _LIBCPP_INLINE_VISIBILITY
    reference operator*() const {
        return __stashed_elem_;
    }

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

    _LIBCPP_INLINE_VISIBILITY
    iterator& operator++() {
        _LIBCPP_ASSERT(__state_ != __singular,
                       "attempting to increment a singular iterator");
        _LIBCPP_ASSERT(__state_ != __at_end,
                      "attempting to increment the end iterator");
        return __increment();
    }

    _LIBCPP_INLINE_VISIBILITY
    iterator operator++(int) {
        iterator __it(*this);
        this->operator++();
        return __it;
    }

    _LIBCPP_INLINE_VISIBILITY
    iterator& operator--() {
        _LIBCPP_ASSERT(__state_ != __singular,
                       "attempting to decrement a singular iterator");
        _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
                       "attempting to decrement the begin iterator");
        return __decrement();
    }

    _LIBCPP_INLINE_VISIBILITY
    iterator operator--(int) {
        iterator __it(*this);
        this->operator--();
        return __it;
    }

private:
    friend class path;

    static constexpr unsigned char __singular = 0;
    static constexpr unsigned char __at_end = 6;

    inline _LIBCPP_INLINE_VISIBILITY
    friend bool operator==(const iterator&, const iterator&);

    iterator& __increment();
    iterator& __decrement();

    path __stashed_elem_;
    const path* __path_ptr_;
    path::__string_view __entry_;
    unsigned char __state_;
};

inline _LIBCPP_INLINE_VISIBILITY
bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) {
    return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
           __lhs.__entry_.data() == __rhs.__entry_.data();
}

inline _LIBCPP_INLINE_VISIBILITY
bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) {
    return !(__lhs == __rhs);
}

class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error
{
public:
    _LIBCPP_INLINE_VISIBILITY
    filesystem_error(const string& __what, error_code __ec)
        : system_error(__ec, __what),
          __paths_(make_shared<_Storage>(path(), path()))
    {}

    _LIBCPP_INLINE_VISIBILITY
    filesystem_error(const string& __what, const path& __p1, error_code __ec)
        : system_error(__ec, __what),
        __paths_(make_shared<_Storage>(__p1, path()))
    {}

    _LIBCPP_INLINE_VISIBILITY
    filesystem_error(const string& __what, const path& __p1, const path& __p2,
                     error_code __ec)
        : system_error(__ec, __what),
          __paths_(make_shared<_Storage>(__p1, __p2))
    {}

    _LIBCPP_INLINE_VISIBILITY
    const path& path1() const _NOEXCEPT {
        return __paths_->first;
    }

    _LIBCPP_INLINE_VISIBILITY
    const path& path2() const _NOEXCEPT {
        return __paths_->second;
    }

    ~filesystem_error() override; // key function

    // TODO(ericwf): Create a custom error message.
    //const char* what() const _NOEXCEPT;

private:
    typedef pair<path, path> _Storage;
    shared_ptr<_Storage> __paths_;
};

template <class... _Args>
_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
#ifndef _LIBCPP_NO_EXCEPTIONS
void __throw_filesystem_error(_Args && ...__args)
{
    throw filesystem_error(std::forward<_Args>(__args)...);
}
#else
void __throw_filesystem_error(_Args&&...)
{
    _VSTD::abort();
}
#endif


// operational functions

_LIBCPP_FUNC_VIS
path __canonical(const path&, const path&, error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
void __copy(const path& __from, const path& __to, copy_options __opt,
        error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
bool __copy_file(const path& __from, const path& __to, copy_options __opt,
        error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
        error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
bool __create_directories(const path& p, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
bool __create_directory(const path& p, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
bool __create_directory(const path& p, const path & attributes,
        error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
void __create_directory_symlink(const path& __to, const path& __new_symlink,
        error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
void __create_hard_link(const path& __to, const path& __new_hard_link,
        error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
void __create_symlink(const path& __to, const path& __new_symlink,
        error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
path __current_path(error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
void __current_path(const path&, error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
bool __equivalent(const path&, const path&, error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
uintmax_t __file_size(const path&, error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
bool __fs_is_empty(const path& p, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
file_time_type __last_write_time(const path& p, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
void __last_write_time(const path& p, file_time_type new_time,
        error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
void __permissions(const path& p, perms prms, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
path __read_symlink(const path& p, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
bool __remove(const path& p, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
uintmax_t __remove_all(const path& p, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
void __rename(const path& from, const path& to, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
space_info __space(const path&, error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
file_status __status(const path&, error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
file_status __symlink_status(const path&, error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
path __system_complete(const path&, error_code *__ec=nullptr);
_LIBCPP_FUNC_VIS
path __temp_directory_path(error_code *__ec=nullptr);

inline _LIBCPP_INLINE_VISIBILITY
path current_path() {
    return __current_path();
}

inline _LIBCPP_INLINE_VISIBILITY
path current_path(error_code& __ec) {
    return __current_path(&__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void current_path(const path& __p) {
    __current_path(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
void current_path(const path& __p, error_code& __ec) _NOEXCEPT {
    __current_path(__p, &__ec);
}

_LIBCPP_FUNC_VIS
path absolute(const path&, const path& __p2 = current_path());

inline _LIBCPP_INLINE_VISIBILITY
path canonical(const path& __p, const path& __base = current_path()) {
    return __canonical(__p, __base);
}

inline _LIBCPP_INLINE_VISIBILITY
path canonical(const path& __p, error_code& __ec) {
    path __base = __current_path(&__ec);
    if (__ec) return {};
    return __canonical(__p, __base, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
path canonical(const path& __p, const path& __base, error_code& __ec) {
    return __canonical(__p, __base, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void copy(const path& __from, const path& __to) {
    __copy(__from, __to, copy_options::none);
}

inline _LIBCPP_INLINE_VISIBILITY
void copy(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
    __copy(__from, __to, copy_options::none, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void copy(const path& __from, const path& __to, copy_options __opt) {
    __copy(__from, __to, __opt);
}

inline _LIBCPP_INLINE_VISIBILITY
void copy(const path& __from, const path& __to,
          copy_options __opt, error_code& __ec) _NOEXCEPT {
    __copy(__from, __to, __opt, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
bool copy_file(const path& __from, const path& __to) {
    return __copy_file(__from, __to, copy_options::none);
}

inline _LIBCPP_INLINE_VISIBILITY
bool copy_file(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
    return __copy_file(__from, __to, copy_options::none, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
bool copy_file(const path& __from, const path& __to, copy_options __opt) {
    return __copy_file(__from, __to, __opt);
}

inline _LIBCPP_INLINE_VISIBILITY
bool copy_file(const path& __from, const path& __to,
               copy_options __opt, error_code& __ec) _NOEXCEPT {
    return __copy_file(__from, __to, __opt, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void copy_symlink(const path& __existing, const path& __new) {
    __copy_symlink(__existing, __new);
}

inline _LIBCPP_INLINE_VISIBILITY
void copy_symlink(const path& __ext, const path& __new, error_code& __ec) _NOEXCEPT {
    __copy_symlink(__ext, __new, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
bool create_directories(const path& __p) {
    return __create_directories(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
bool create_directories(const path& __p, error_code& __ec) _NOEXCEPT {
    return __create_directories(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
bool create_directory(const path& __p) {
    return __create_directory(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
bool create_directory(const path& __p, error_code& __ec) _NOEXCEPT {
    return __create_directory(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
bool create_directory(const path& __p, const path& __attrs) {
    return __create_directory(__p, __attrs);
}

inline _LIBCPP_INLINE_VISIBILITY
bool create_directory(const path& __p, const path& __attrs, error_code& __ec) _NOEXCEPT {
    return __create_directory(__p, __attrs, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void create_directory_symlink(const path& __to, const path& __new) {
    __create_directory_symlink(__to, __new);
}

inline _LIBCPP_INLINE_VISIBILITY
void create_directory_symlink(const path& __to, const path& __new,
                              error_code& __ec) _NOEXCEPT {
    __create_directory_symlink(__to, __new, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void create_hard_link(const path& __to, const path& __new) {
    __create_hard_link(__to, __new);
}

inline _LIBCPP_INLINE_VISIBILITY
void create_hard_link(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
    __create_hard_link(__to, __new, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void create_symlink(const path& __to, const path& __new) {
    __create_symlink(__to, __new);
}

inline _LIBCPP_INLINE_VISIBILITY
void create_symlink(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
    return __create_symlink(__to, __new, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
bool status_known(file_status __s) _NOEXCEPT {
    return __s.type() != file_type::none;
}

inline _LIBCPP_INLINE_VISIBILITY
bool exists(file_status __s) _NOEXCEPT {
    return status_known(__s) && __s.type() != file_type::not_found;
}

inline _LIBCPP_INLINE_VISIBILITY
bool exists(const path& __p) {
    return exists(__status(__p));
}

inline _LIBCPP_INLINE_VISIBILITY
bool exists(const path& __p, error_code& __ec) _NOEXCEPT {
    auto __s = __status(__p, &__ec);
    if (status_known(__s)) __ec.clear();
    return exists(__s);
}

inline _LIBCPP_INLINE_VISIBILITY
bool equivalent(const path& __p1, const path& __p2) {
    return __equivalent(__p1, __p2);
}

inline _LIBCPP_INLINE_VISIBILITY
bool equivalent(const path& __p1, const path& __p2, error_code& __ec) _NOEXCEPT {
    return __equivalent(__p1, __p2, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
uintmax_t file_size(const path& __p) {
    return __file_size(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
uintmax_t file_size(const path& __p, error_code& __ec) _NOEXCEPT {
    return __file_size(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
uintmax_t hard_link_count(const path& __p) {
    return __hard_link_count(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
uintmax_t hard_link_count(const path& __p, error_code& __ec) _NOEXCEPT {
    return __hard_link_count(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_block_file(file_status __s) _NOEXCEPT {
    return __s.type() == file_type::block;
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_block_file(const path& __p) {
    return is_block_file(__status(__p));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_block_file(const path& __p, error_code& __ec) _NOEXCEPT {
    return is_block_file(__status(__p, &__ec));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_character_file(file_status __s) _NOEXCEPT {
    return __s.type() == file_type::character;
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_character_file(const path& __p) {
    return is_character_file(__status(__p));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_character_file(const path& __p, error_code& __ec) _NOEXCEPT {
    return is_character_file(__status(__p, &__ec));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_directory(file_status __s) _NOEXCEPT {
    return __s.type() == file_type::directory;
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_directory(const path& __p) {
    return is_directory(__status(__p));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_directory(const path& __p, error_code& __ec) _NOEXCEPT {
    return is_directory(__status(__p, &__ec));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_empty(const path& __p) {
    return __fs_is_empty(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_empty(const path& __p, error_code& __ec) _NOEXCEPT {
    return __fs_is_empty(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_fifo(file_status __s) _NOEXCEPT {
    return __s.type() == file_type::fifo;
}
inline _LIBCPP_INLINE_VISIBILITY
bool is_fifo(const path& __p) {
    return is_fifo(__status(__p));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_fifo(const path& __p, error_code& __ec) _NOEXCEPT {
    return is_fifo(__status(__p, &__ec));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_regular_file(file_status __s) _NOEXCEPT {
    return __s.type() == file_type::regular;
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_regular_file(const path& __p) {
    return is_regular_file(__status(__p));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_regular_file(const path& __p, error_code& __ec) _NOEXCEPT {
    return is_regular_file(__status(__p, &__ec));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_socket(file_status __s) _NOEXCEPT {
    return __s.type() == file_type::socket;
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_socket(const path& __p) {
    return is_socket(__status(__p));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_socket(const path& __p, error_code& __ec) _NOEXCEPT {
    return is_socket(__status(__p, &__ec));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_symlink(file_status __s) _NOEXCEPT {
    return __s.type() == file_type::symlink;
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_symlink(const path& __p) {
    return is_symlink(__symlink_status(__p));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_symlink(const path& __p, error_code& __ec) _NOEXCEPT {
    return is_symlink(__symlink_status(__p, &__ec));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_other(file_status __s) _NOEXCEPT {
    return exists(__s)
        && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s);
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_other(const path& __p) {
    return is_other(__status(__p));
}

inline _LIBCPP_INLINE_VISIBILITY
bool is_other(const path& __p, error_code& __ec) _NOEXCEPT {
    return is_other(__status(__p, &__ec));
}

inline _LIBCPP_INLINE_VISIBILITY
file_time_type last_write_time(const path& __p) {
    return __last_write_time(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
file_time_type last_write_time(const path& __p, error_code& __ec) _NOEXCEPT {
    return __last_write_time(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void last_write_time(const path& __p, file_time_type __t) {
    __last_write_time(__p, __t);
}

inline _LIBCPP_INLINE_VISIBILITY
void last_write_time(const path& __p, file_time_type __t, error_code& __ec) _NOEXCEPT {
    __last_write_time(__p, __t, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void permissions(const path& __p, perms __prms) {
    __permissions(__p, __prms);
}

inline _LIBCPP_INLINE_VISIBILITY
void permissions(const path& __p, perms __prms, error_code& __ec)  {
    __permissions(__p, __prms, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
path read_symlink(const path& __p) {
    return __read_symlink(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
path read_symlink(const path& __p, error_code& __ec) {
    return __read_symlink(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
bool remove(const path& __p) {
    return __remove(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
bool remove(const path& __p, error_code& __ec) _NOEXCEPT {
    return __remove(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
uintmax_t remove_all(const path& __p) {
    return __remove_all(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
uintmax_t remove_all(const path& __p, error_code& __ec) _NOEXCEPT {
    return __remove_all(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void rename(const path& __from, const path& __to) {
    return __rename(__from, __to);
}

inline _LIBCPP_INLINE_VISIBILITY
void rename(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
    return __rename(__from, __to, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
void resize_file(const path& __p, uintmax_t __ns) {
    return __resize_file(__p, __ns);
}

inline _LIBCPP_INLINE_VISIBILITY
void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) _NOEXCEPT {
    return __resize_file(__p, __ns, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
space_info space(const path& __p) {
    return __space(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
space_info space(const path& __p, error_code& __ec) _NOEXCEPT {
    return __space(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
file_status status(const path& __p) {
    return __status(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
file_status status(const path& __p, error_code& __ec) _NOEXCEPT {
    return __status(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
file_status symlink_status(const path& __p) {
    return __symlink_status(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
file_status symlink_status(const path& __p, error_code& __ec) _NOEXCEPT {
    return __symlink_status(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
path system_complete(const path& __p) {
    return __system_complete(__p);
}

inline _LIBCPP_INLINE_VISIBILITY
path system_complete(const path& __p, error_code& __ec) {
    return __system_complete(__p, &__ec);
}

inline _LIBCPP_INLINE_VISIBILITY
path temp_directory_path() {
    return __temp_directory_path();
}

inline _LIBCPP_INLINE_VISIBILITY
path temp_directory_path(error_code& __ec) {
    return __temp_directory_path(&__ec);
}


class directory_entry
{
    typedef _VSTD_FS::path _Path;

public:
    // constructors and destructors
    directory_entry() _NOEXCEPT = default;
    directory_entry(directory_entry const&) = default;
    directory_entry(directory_entry&&) _NOEXCEPT = default;

    _LIBCPP_INLINE_VISIBILITY
    explicit directory_entry(_Path const& __p) : __p_(__p) {}

    ~directory_entry() {}

    directory_entry& operator=(directory_entry const&) = default;
    directory_entry& operator=(directory_entry&&) _NOEXCEPT = default;

    _LIBCPP_INLINE_VISIBILITY
    void assign(_Path const& __p) {
        __p_ = __p;
    }

    _LIBCPP_INLINE_VISIBILITY
    void replace_filename(_Path const& __p) {
        __p_ = __p_.parent_path() / __p;
    }

    _LIBCPP_INLINE_VISIBILITY
    _Path const& path() const _NOEXCEPT {
        return __p_;
    }

    _LIBCPP_INLINE_VISIBILITY
    operator const _Path&() const _NOEXCEPT {
        return __p_;
    }

    _LIBCPP_INLINE_VISIBILITY
    file_status status() const {
        return _VSTD_FS::status(__p_);
    }

    _LIBCPP_INLINE_VISIBILITY
    file_status status(error_code& __ec) const _NOEXCEPT {
        return _VSTD_FS::status(__p_, __ec);
    }

    _LIBCPP_INLINE_VISIBILITY
    file_status symlink_status() const {
        return _VSTD_FS::symlink_status(__p_);
    }

    _LIBCPP_INLINE_VISIBILITY
    file_status symlink_status(error_code& __ec) const _NOEXCEPT {
        return _VSTD_FS::symlink_status(__p_, __ec);
    }

    _LIBCPP_INLINE_VISIBILITY
    bool operator< (directory_entry const& __rhs) const _NOEXCEPT {
        return __p_ < __rhs.__p_;
    }

    _LIBCPP_INLINE_VISIBILITY
    bool operator==(directory_entry const& __rhs) const _NOEXCEPT {
        return __p_ == __rhs.__p_;
    }

    _LIBCPP_INLINE_VISIBILITY
    bool operator!=(directory_entry const& __rhs) const _NOEXCEPT {
        return __p_ != __rhs.__p_;
    }

    _LIBCPP_INLINE_VISIBILITY
    bool operator<=(directory_entry const& __rhs) const _NOEXCEPT {
        return __p_ <= __rhs.__p_;
    }

    _LIBCPP_INLINE_VISIBILITY
    bool operator> (directory_entry const& __rhs) const _NOEXCEPT {
        return __p_ > __rhs.__p_;
    }

    _LIBCPP_INLINE_VISIBILITY
    bool operator>=(directory_entry const& __rhs) const _NOEXCEPT {
        return __p_ >= __rhs.__p_;
    }
private:
    _Path __p_;
};


class directory_iterator;
class recursive_directory_iterator;
class __dir_stream;

class __dir_element_proxy {
public:

    inline _LIBCPP_INLINE_VISIBILITY
    directory_entry operator*() { return _VSTD::move(__elem_); }

private:
    friend class directory_iterator;
    friend class recursive_directory_iterator;
    explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
    __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {}
    directory_entry __elem_;
};

class directory_iterator
{
public:
    typedef directory_entry value_type;
    typedef ptrdiff_t difference_type;
    typedef value_type const* pointer;
    typedef value_type const& reference;
    typedef input_iterator_tag iterator_category;

public:
    //ctor & dtor
    directory_iterator() _NOEXCEPT
    { }

    explicit directory_iterator(const path& __p)
        : directory_iterator(__p, nullptr)
    { }

    directory_iterator(const path& __p, directory_options __opts)
        : directory_iterator(__p, nullptr, __opts)
    { }

    directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT
        : directory_iterator(__p, &__ec)
    { }

    directory_iterator(const path& __p, directory_options __opts,
                       error_code& __ec) _NOEXCEPT
        : directory_iterator(__p, &__ec, __opts)
    { }

    directory_iterator(const directory_iterator&) = default;
    directory_iterator(directory_iterator&&) = default;
    directory_iterator& operator=(const directory_iterator&) = default;

    directory_iterator& operator=(directory_iterator&& __o) _NOEXCEPT {
        // non-default implementation provided to support self-move assign.
        if (this != &__o) {
            __imp_ = _VSTD::move(__o.__imp_);
        }
        return *this;
    }

    ~directory_iterator() = default;

    const directory_entry& operator*() const {
        _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
        return __dereference();
    }

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

    directory_iterator& operator++()
    { return __increment(); }

    __dir_element_proxy operator++(int) {
        __dir_element_proxy __p(**this);
        __increment();
        return __p;
    }

    directory_iterator& increment(error_code& __ec) _NOEXCEPT
    { return __increment(&__ec); }

private:
    inline _LIBCPP_INLINE_VISIBILITY
    friend bool operator==(const directory_iterator& __lhs,
                           const directory_iterator& __rhs) _NOEXCEPT;

    // construct the dir_stream
    _LIBCPP_FUNC_VIS
    directory_iterator(const path&, error_code *,
                       directory_options = directory_options::none);

    _LIBCPP_FUNC_VIS
    directory_iterator& __increment(error_code * __ec = nullptr);

    _LIBCPP_FUNC_VIS
    const directory_entry& __dereference() const;

private:
    shared_ptr<__dir_stream> __imp_;
};


inline _LIBCPP_INLINE_VISIBILITY
bool operator==(const directory_iterator& __lhs,
                const directory_iterator& __rhs) _NOEXCEPT {
    return __lhs.__imp_ == __rhs.__imp_;
}

inline _LIBCPP_INLINE_VISIBILITY
bool operator!=(const directory_iterator& __lhs,
                const directory_iterator& __rhs) _NOEXCEPT {
    return !(__lhs == __rhs);
}

// enable directory_iterator range-based for statements
inline _LIBCPP_INLINE_VISIBILITY
directory_iterator begin(directory_iterator __iter) _NOEXCEPT {
    return __iter;
}

inline _LIBCPP_INLINE_VISIBILITY
directory_iterator end(const directory_iterator&) _NOEXCEPT {
    return directory_iterator();
}

class recursive_directory_iterator {
public:
    using value_type = directory_entry;
    using difference_type = std::ptrdiff_t;
    using pointer = directory_entry const *;
    using reference = directory_entry const &;
    using iterator_category = std::input_iterator_tag;

public:
    // constructors and destructor
    _LIBCPP_INLINE_VISIBILITY
    recursive_directory_iterator()  _NOEXCEPT
        : __rec_(false)
    {}

    _LIBCPP_INLINE_VISIBILITY
    explicit recursive_directory_iterator(const path& __p,
                directory_options __xoptions = directory_options::none)
        : recursive_directory_iterator(__p, __xoptions,  nullptr)
    { }

    _LIBCPP_INLINE_VISIBILITY
    recursive_directory_iterator(const path& __p,
        directory_options __xoptions, error_code& __ec) _NOEXCEPT
        : recursive_directory_iterator(__p, __xoptions, &__ec)
    { }

    _LIBCPP_INLINE_VISIBILITY
    recursive_directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT
        : recursive_directory_iterator(__p, directory_options::none,  &__ec)
    { }

    recursive_directory_iterator(const recursive_directory_iterator&) = default;
    recursive_directory_iterator(recursive_directory_iterator&&) = default;

    recursive_directory_iterator &
    operator=(const recursive_directory_iterator&) = default;

    _LIBCPP_INLINE_VISIBILITY
    recursive_directory_iterator &
    operator=(recursive_directory_iterator&& __o) noexcept {
        // non-default implementation provided to support self-move assign.
        if (this != &__o) {
            __imp_ = _VSTD::move(__o.__imp_);
            __rec_ = __o.__rec_;
        }
        return *this;
    }

    ~recursive_directory_iterator() = default;

    _LIBCPP_INLINE_VISIBILITY
    const directory_entry& operator*() const
    { return __dereference(); }

    _LIBCPP_INLINE_VISIBILITY
    const directory_entry* operator->() const
    { return &__dereference(); }

    recursive_directory_iterator& operator++()
    { return __increment(); }

    _LIBCPP_INLINE_VISIBILITY
    __dir_element_proxy operator++(int) {
        __dir_element_proxy __p(**this);
        __increment();
        return __p;
    }

    _LIBCPP_INLINE_VISIBILITY
    recursive_directory_iterator& increment(error_code& __ec) _NOEXCEPT
    { return __increment(&__ec); }

    _LIBCPP_FUNC_VIS directory_options options() const;
    _LIBCPP_FUNC_VIS int  depth() const;

    _LIBCPP_INLINE_VISIBILITY
    void pop() { __pop(); }

    _LIBCPP_INLINE_VISIBILITY
    void pop(error_code& __ec)
    { __pop(&__ec); }

    _LIBCPP_INLINE_VISIBILITY
    bool recursion_pending() const
    { return __rec_; }

    _LIBCPP_INLINE_VISIBILITY
    void disable_recursion_pending()
    { __rec_ = false; }

private:
    recursive_directory_iterator(const path& __p, directory_options __opt,
                                 error_code *__ec);

    _LIBCPP_FUNC_VIS
    const directory_entry& __dereference() const;

    _LIBCPP_FUNC_VIS
    bool __try_recursion(error_code* __ec);

    _LIBCPP_FUNC_VIS
    void __advance(error_code* __ec=nullptr);

    _LIBCPP_FUNC_VIS
    recursive_directory_iterator& __increment(error_code *__ec=nullptr);

    _LIBCPP_FUNC_VIS
    void __pop(error_code* __ec=nullptr);

    inline _LIBCPP_INLINE_VISIBILITY
    friend bool operator==(const recursive_directory_iterator&,
                           const recursive_directory_iterator&) _NOEXCEPT;

    struct __shared_imp;
    shared_ptr<__shared_imp> __imp_;
    bool __rec_;
};                                     // class recursive_directory_iterator


inline _LIBCPP_INLINE_VISIBILITY
bool operator==(const recursive_directory_iterator& __lhs,
                const recursive_directory_iterator& __rhs) _NOEXCEPT
{
    return __lhs.__imp_ == __rhs.__imp_;
}

_LIBCPP_INLINE_VISIBILITY
inline bool operator!=(const recursive_directory_iterator& __lhs,
                        const recursive_directory_iterator& __rhs) _NOEXCEPT
{
    return !(__lhs == __rhs);
}
// enable recursive_directory_iterator range-based for statements
inline _LIBCPP_INLINE_VISIBILITY
recursive_directory_iterator begin(recursive_directory_iterator __iter) _NOEXCEPT {
    return __iter;
}

inline _LIBCPP_INLINE_VISIBILITY
recursive_directory_iterator end(const recursive_directory_iterator&) _NOEXCEPT {
    return recursive_directory_iterator();
}

_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM

#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM