boost_filesystem 0.1.0

Boost C++ library boost_filesystem packaged using Zanbil
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
//  filesystem path.hpp  ---------------------------------------------------------------//

//  Copyright Vladimir Prus 2002
//  Copyright Beman Dawes 2002-2005, 2009
//  Copyright Andrey Semashev 2021-2024

//  Distributed under the Boost Software License, Version 1.0.
//  See http://www.boost.org/LICENSE_1_0.txt

//  Library home page: http://www.boost.org/libs/filesystem

//  path::stem(), extension(), and replace_extension() are based on
//  basename(), extension(), and change_extension() from the original
//  filesystem/convenience.hpp header by Vladimir Prus.

#ifndef BOOST_FILESYSTEM_PATH_HPP
#define BOOST_FILESYSTEM_PATH_HPP

#include <boost/filesystem/config.hpp>
#include <cstddef>
#include <iosfwd>
#include <locale>
#include <string>
#include <iterator>
#include <type_traits>
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
#include <string_view>
#endif
#include <boost/assert.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <boost/io/quoted.hpp>
#include <boost/functional/hash_fwd.hpp>
#include <boost/filesystem/detail/path_traits.hpp>
#include <boost/filesystem/detail/type_traits/negation.hpp>
#include <boost/filesystem/detail/type_traits/conjunction.hpp>
#include <boost/filesystem/detail/type_traits/disjunction.hpp>

#include <boost/filesystem/detail/header.hpp> // must be the last #include

namespace boost {
namespace filesystem {

class path;

namespace path_detail { // intentionally don't use filesystem::detail to not bring internal Boost.Filesystem functions into ADL via path_constants

template< typename Char, Char Separator, Char PreferredSeparator, Char Dot >
struct path_constants
{
    typedef path_constants< Char, Separator, PreferredSeparator, Dot > path_constants_base;
    typedef Char value_type;
    static BOOST_CONSTEXPR_OR_CONST value_type separator = Separator;
    static BOOST_CONSTEXPR_OR_CONST value_type preferred_separator = PreferredSeparator;
    static BOOST_CONSTEXPR_OR_CONST value_type dot = Dot;
};

#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
template< typename Char, Char Separator, Char PreferredSeparator, Char Dot >
BOOST_CONSTEXPR_OR_CONST typename path_constants< Char, Separator, PreferredSeparator, Dot >::value_type
path_constants< Char, Separator, PreferredSeparator, Dot >::separator;
template< typename Char, Char Separator, Char PreferredSeparator, Char Dot >
BOOST_CONSTEXPR_OR_CONST typename path_constants< Char, Separator, PreferredSeparator, Dot >::value_type
path_constants< Char, Separator, PreferredSeparator, Dot >::preferred_separator;
template< typename Char, Char Separator, Char PreferredSeparator, Char Dot >
BOOST_CONSTEXPR_OR_CONST typename path_constants< Char, Separator, PreferredSeparator, Dot >::value_type
path_constants< Char, Separator, PreferredSeparator, Dot >::dot;
#endif

class path_iterator;
class path_reverse_iterator;

} // namespace path_detail

namespace detail {

struct path_algorithms
{
    // A struct that denotes a contiguous range of characters in a string. A lightweight alternative to string_view.
    struct substring
    {
        std::size_t pos;
        std::size_t size;
    };

    typedef path_traits::path_native_char_type value_type;
    typedef std::basic_string< value_type > string_type;

    static bool has_filename_v3(path const& p);
    static bool has_filename_v4(path const& p);
    BOOST_FILESYSTEM_DECL static path filename_v3(path const& p);
    static path filename_v4(path const& p);

    BOOST_FILESYSTEM_DECL static path stem_v3(path const& p);
    BOOST_FILESYSTEM_DECL static path stem_v4(path const& p);
    BOOST_FILESYSTEM_DECL static path extension_v3(path const& p);
    static path extension_v4(path const& p);

    BOOST_FILESYSTEM_DECL static void remove_filename_v3(path& p);
    BOOST_FILESYSTEM_DECL static void remove_filename_v4(path& p);

    BOOST_FILESYSTEM_DECL static void replace_extension_v3(path& p, path const& new_extension);
    BOOST_FILESYSTEM_DECL static void replace_extension_v4(path& p, path const& new_extension);

    BOOST_FILESYSTEM_DECL static path lexically_normal_v3(path const& p);
    BOOST_FILESYSTEM_DECL static path lexically_normal_v4(path const& p);

    BOOST_FILESYSTEM_DECL static path generic_path_v3(path const& p);
    BOOST_FILESYSTEM_DECL static path generic_path_v4(path const& p);

#if defined(BOOST_WINDOWS_API)
    BOOST_FILESYSTEM_DECL static void make_preferred_v3(path& p);
    BOOST_FILESYSTEM_DECL static void make_preferred_v4(path& p);
#endif

    BOOST_FILESYSTEM_DECL static int compare_v3(path const& left, path const& right);
    BOOST_FILESYSTEM_DECL static int compare_v4(path const& left, path const& right);

    BOOST_FILESYSTEM_DECL static void append_v3(path& p, const value_type* b, const value_type* e);
    BOOST_FILESYSTEM_DECL static void append_v4(path& p, const value_type* b, const value_type* e);
    static void append_v4(path& left, path const& right);

    //  Returns: If separator is to be appended, m_pathname.size() before append. Otherwise 0.
    //  Note: An append is never performed if size()==0, so a returned 0 is unambiguous.
    BOOST_FILESYSTEM_DECL static string_type::size_type append_separator_if_needed(path& p);
    BOOST_FILESYSTEM_DECL static void erase_redundant_separator(path& p, string_type::size_type sep_pos);

    BOOST_FILESYSTEM_DECL static string_type::size_type find_root_name_size(path const& p);
    BOOST_FILESYSTEM_DECL static string_type::size_type find_root_path_size(path const& p);
    BOOST_FILESYSTEM_DECL static substring find_root_directory(path const& p);
    BOOST_FILESYSTEM_DECL static substring find_relative_path(path const& p);
    BOOST_FILESYSTEM_DECL static string_type::size_type find_parent_path_size(path const& p);
    BOOST_FILESYSTEM_DECL static string_type::size_type find_filename_v4_size(path const& p);
    BOOST_FILESYSTEM_DECL static string_type::size_type find_extension_v4_size(path const& p);

    BOOST_FILESYSTEM_DECL static int lex_compare_v3
    (
        path_detail::path_iterator first1, path_detail::path_iterator const& last1,
        path_detail::path_iterator first2, path_detail::path_iterator const& last2
    );
    BOOST_FILESYSTEM_DECL static int lex_compare_v4
    (
        path_detail::path_iterator first1, path_detail::path_iterator const& last1,
        path_detail::path_iterator first2, path_detail::path_iterator const& last2
    );

    BOOST_FILESYSTEM_DECL static void increment_v3(path_detail::path_iterator& it);
    BOOST_FILESYSTEM_DECL static void increment_v4(path_detail::path_iterator& it);
    BOOST_FILESYSTEM_DECL static void decrement_v3(path_detail::path_iterator& it);
    BOOST_FILESYSTEM_DECL static void decrement_v4(path_detail::path_iterator& it);
};

} // namespace detail

//------------------------------------------------------------------------------------//
//                                                                                    //
//                                    class path                                      //
//                                                                                    //
//------------------------------------------------------------------------------------//

class path :
    public filesystem::path_detail::path_constants<
#ifdef BOOST_WINDOWS_API
        detail::path_traits::path_native_char_type, L'/', L'\\', L'.'
#else
        detail::path_traits::path_native_char_type, '/', '/', '.'
#endif
    >
{
    friend class path_detail::path_iterator;
    friend class path_detail::path_reverse_iterator;
    friend struct detail::path_algorithms;

public:
    //  value_type is the character type used by the operating system API to
    //  represent paths.

    typedef detail::path_algorithms::value_type value_type;
    typedef detail::path_algorithms::string_type string_type;
    typedef detail::path_traits::codecvt_type codecvt_type;

    //  ----- character encoding conversions -----

    //  Following the principle of least astonishment, path input arguments
    //  passed to or obtained from the operating system via objects of
    //  class path behave as if they were directly passed to or
    //  obtained from the O/S API, unless conversion is explicitly requested.
    //
    //  POSIX specfies that path strings are passed unchanged to and from the
    //  API. Note that this is different from the POSIX command line utilities,
    //  which convert according to a locale.
    //
    //  Thus for POSIX, char strings do not undergo conversion.  wchar_t strings
    //  are converted to/from char using the path locale or, if a conversion
    //  argument is given, using a conversion object modeled on
    //  std::wstring_convert.
    //
    //  The path locale, which is global to the thread, can be changed by the
    //  imbue() function. It is initialized to an implementation defined locale.
    //
    //  For Windows, wchar_t strings do not undergo conversion. char strings
    //  are converted using the "ANSI" or "OEM" code pages, as determined by
    //  the AreFileApisANSI() function, or, if a conversion argument is given,
    //  using a conversion object modeled on std::wstring_convert.
    //
    //  See m_pathname comments for further important rationale.

    //  TODO: rules needed for operating systems that use / or .
    //  differently, or format directory paths differently from file paths.
    //
    //  **********************************************************************************
    //
    //  More work needed: How to handle an operating system that may have
    //  slash characters or dot characters in valid filenames, either because
    //  it doesn't follow the POSIX standard, or because it allows MBCS
    //  filename encodings that may contain slash or dot characters. For
    //  example, ISO/IEC 2022 (JIS) encoding which allows switching to
    //  JIS x0208-1983 encoding. A valid filename in this set of encodings is
    //  0x1B 0x24 0x42 [switch to X0208-1983] 0x24 0x2F [U+304F Kiragana letter KU]
    //                                             ^^^^
    //  Note that 0x2F is the ASCII slash character
    //
    //  **********************************************************************************

    //  Supported source arguments: half-open iterator range, container, c-array,
    //  and single pointer to null terminated string.

    //  All source arguments except pointers to null terminated byte strings support
    //  multi-byte character strings which may have embedded nulls. Embedded null
    //  support is required for some Asian languages on Windows.

    //  "const codecvt_type& cvt=codecvt()" default arguments are not used because this
    //  limits the impact of locale("") initialization failures on POSIX systems to programs
    //  that actually depend on locale(""). It further ensures that exceptions thrown
    //  as a result of such failues occur after main() has started, so can be caught.

private:
    //! Assignment operation
    class assign_op
    {
    private:
        path& m_self;

    public:
        typedef void result_type;

        explicit assign_op(path& self) noexcept : m_self(self) {}

        result_type operator() (const value_type* source, const value_type* source_end, const codecvt_type* = nullptr) const
        {
            m_self.m_pathname.assign(source, source_end);
        }

        template< typename OtherChar >
        result_type operator() (const OtherChar* source, const OtherChar* source_end, const codecvt_type* cvt = nullptr) const
        {
            m_self.m_pathname.clear();
            detail::path_traits::convert(source, source_end, m_self.m_pathname, cvt);
        }
    };

    //! Concatenation operation
    class concat_op
    {
    private:
        path& m_self;

    public:
        typedef void result_type;

        explicit concat_op(path& self) noexcept : m_self(self) {}

        result_type operator() (const value_type* source, const value_type* source_end, const codecvt_type* = nullptr) const
        {
            m_self.m_pathname.append(source, source_end);
        }

        template< typename OtherChar >
        result_type operator() (const OtherChar* source, const OtherChar* source_end, const codecvt_type* cvt = nullptr) const
        {
            detail::path_traits::convert(source, source_end, m_self.m_pathname, cvt);
        }
    };

    //! Path appending operation
    class append_op
    {
    private:
        path& m_self;

    public:
        typedef void result_type;

        explicit append_op(path& self) noexcept : m_self(self) {}

        BOOST_FORCEINLINE result_type operator() (const value_type* source, const value_type* source_end, const codecvt_type* = nullptr) const
        {
            m_self.append(source, source_end);
        }

        template< typename OtherChar >
        BOOST_FORCEINLINE result_type operator() (const OtherChar* source, const OtherChar* source_end, const codecvt_type* cvt = nullptr) const
        {
            string_type src;
            detail::path_traits::convert(source, source_end, src, cvt);
            m_self.append(src.data(), src.data() + src.size());
        }
    };

    //! Path comparison operation
    class compare_op
    {
    private:
        path const& m_self;

    public:
        typedef int result_type;

        explicit compare_op(path const& self) noexcept : m_self(self) {}

        result_type operator() (const value_type* source, const value_type* source_end, const codecvt_type* = nullptr) const;

        template< typename OtherChar >
        result_type operator() (const OtherChar* source, const OtherChar* source_end, const codecvt_type* cvt = nullptr) const;
    };

public:
    typedef path_detail::path_iterator iterator;
    typedef iterator const_iterator;
    typedef path_detail::path_reverse_iterator reverse_iterator;
    typedef reverse_iterator const_reverse_iterator;

public:
    //  -----  constructors  -----

    path() noexcept {}
    path(path const& p) : m_pathname(p.m_pathname) {}
    path(path const& p, codecvt_type const&) : m_pathname(p.m_pathname) {}

    path(const value_type* s) : m_pathname(s) {}
    path(const value_type* s, codecvt_type const&) : m_pathname(s) {}
    path(string_type const& s) : m_pathname(s) {}
    path(string_type const& s, codecvt_type const&) : m_pathname(s) {}
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
    path(std::basic_string_view< value_type > const& s) : m_pathname(s) {}
    path(std::basic_string_view< value_type > const& s, codecvt_type const&) : m_pathname(s) {}
#endif

    template<
        typename Source,
        typename = typename std::enable_if<
            detail::conjunction<
                detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >,
                detail::negation< detail::path_traits::is_native_path_source< typename std::remove_cv< Source >::type > >
            >::value
        >::type
    >
    path(Source const& source)
    {
        assign(source);
    }

    template<
        typename Source,
        typename = typename std::enable_if<
            detail::conjunction<
                detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >,
                detail::negation< detail::path_traits::is_native_path_source< typename std::remove_cv< Source >::type > >
            >::value
        >::type
    >
    explicit path(Source const& source, codecvt_type const& cvt)
    {
        assign(source, cvt);
    }

    path(path&& p) noexcept : m_pathname(static_cast< string_type&& >(p.m_pathname))
    {
    }
    path(path&& p, codecvt_type const&) noexcept : m_pathname(static_cast< string_type&& >(p.m_pathname))
    {
    }
    path& operator=(path&& p) noexcept
    {
        m_pathname = static_cast< string_type&& >(p.m_pathname);
        return *this;
    }
    path& assign(path&& p) noexcept
    {
        m_pathname = static_cast< string_type&& >(p.m_pathname);
        return *this;
    }
    path& assign(path&& p, codecvt_type const&) noexcept
    {
        m_pathname = static_cast< string_type&& >(p.m_pathname);
        return *this;
    }

    path(string_type&& s) noexcept : m_pathname(static_cast< string_type&& >(s))
    {
    }
    path(string_type&& s, codecvt_type const&) noexcept : m_pathname(static_cast< string_type&& >(s))
    {
    }
    path& operator=(string_type&& p) noexcept
    {
        m_pathname = static_cast< string_type&& >(p);
        return *this;
    }
    path& assign(string_type&& p) noexcept
    {
        m_pathname = static_cast< string_type&& >(p);
        return *this;
    }
    path& assign(string_type&& p, codecvt_type const&) noexcept
    {
        m_pathname = static_cast< string_type&& >(p);
        return *this;
    }

    path(const value_type* begin, const value_type* end) : m_pathname(begin, end) {}
    path(const value_type* begin, const value_type* end, codecvt_type const&) : m_pathname(begin, end) {}

    template<
        typename InputIterator,
        typename = typename std::enable_if<
            detail::conjunction<
                detail::path_traits::is_path_source_iterator< InputIterator >,
                detail::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
            >::value
        >::type
    >
    path(InputIterator begin, InputIterator end)
    {
        if (begin != end)
        {
            typedef std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source_t;
            source_t source(begin, end);
            assign(static_cast< source_t&& >(source));
        }
    }

    template<
        typename InputIterator,
        typename = typename std::enable_if<
            detail::conjunction<
                detail::path_traits::is_path_source_iterator< InputIterator >,
                detail::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
            >::value
        >::type
    >
    path(InputIterator begin, InputIterator end, codecvt_type const& cvt)
    {
        if (begin != end)
        {
            typedef std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source_t;
            source_t source(begin, end);
            assign(static_cast< source_t&& >(source), cvt);
        }
    }

    path(std::nullptr_t) = delete;
    path& operator= (std::nullptr_t) = delete;

public:
    //  -----  assignments  -----

    // We need to explicitly define copy assignment as otherwise it will be implicitly defined as deleted because there is move assignment
    path& operator=(path const& p);

    template< typename Source >
    typename std::enable_if<
        detail::disjunction<
            detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >,
            detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
        >::value,
        path&
    >::type operator=(Source const& source)
    {
        return assign(source);
    }

    path& assign(path const& p)
    {
        m_pathname = p.m_pathname;
        return *this;
    }

    template< typename Source >
    typename std::enable_if<
        detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >::value,
        path&
    >::type assign(Source const& source)
    {
        detail::path_traits::dispatch(source, assign_op(*this));
        return *this;
    }

    template< typename Source >
    typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >,
            detail::negation< detail::path_traits::is_path_source< typename std::remove_cv< Source >::type > >
        >::value,
        path&
    >::type assign(Source const& source)
    {
        detail::path_traits::dispatch_convertible(source, assign_op(*this));
        return *this;
    }

    path& assign(path const& p, codecvt_type const&)
    {
        m_pathname = p.m_pathname;
        return *this;
    }

    template< typename Source >
    typename std::enable_if<
        detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >::value,
        path&
    >::type assign(Source const& source, codecvt_type const& cvt)
    {
        detail::path_traits::dispatch(source, assign_op(*this), &cvt);
        return *this;
    }

    template< typename Source >
    typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >,
            detail::negation< detail::path_traits::is_path_source< typename std::remove_cv< Source >::type > >
        >::value,
        path&
    >::type assign(Source const& source, codecvt_type const& cvt)
    {
        detail::path_traits::dispatch_convertible(source, assign_op(*this), &cvt);
        return *this;
    }

    path& assign(const value_type* begin, const value_type* end)
    {
        m_pathname.assign(begin, end);
        return *this;
    }

    template< typename InputIterator >
    typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_path_source_iterator< InputIterator >,
            detail::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
        >::value,
        path&
    >::type assign(InputIterator begin, InputIterator end)
    {
        m_pathname.clear();
        if (begin != end)
        {
            typedef std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source_t;
            source_t source(begin, end);
            assign(static_cast< source_t&& >(source));
        }
        return *this;
    }

    path& assign(const value_type* begin, const value_type* end, codecvt_type const&)
    {
        m_pathname.assign(begin, end);
        return *this;
    }

    template< typename InputIterator >
    typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_path_source_iterator< InputIterator >,
            detail::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
        >::value,
        path&
    >::type assign(InputIterator begin, InputIterator end, codecvt_type const& cvt)
    {
        m_pathname.clear();
        if (begin != end)
        {
            typedef std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source_t;
            source_t source(begin, end);
            assign(static_cast< source_t&& >(source), cvt);
        }
        return *this;
    }

    //  -----  concatenation  -----

    path& operator+=(path const& p);

    template< typename Source >
    typename std::enable_if<
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >::value,
        path&
    >::type operator+=(Source const& source)
    {
        return concat(source);
    }

    path& operator+=(value_type c)
    {
        m_pathname.push_back(c);
        return *this;
    }

    template< typename CharT >
    typename std::enable_if<
        detail::path_traits::is_path_char_type< CharT >::value,
        path&
    >::type operator+=(CharT c)
    {
        CharT tmp[2];
        tmp[0] = c;
        tmp[1] = static_cast< CharT >(0);
        concat_op(*this)(tmp, tmp + 1);
        return *this;
    }

    path& concat(path const& p)
    {
        m_pathname.append(p.m_pathname);
        return *this;
    }

    template< typename Source >
    typename std::enable_if<
        detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >::value,
        path&
    >::type concat(Source const& source)
    {
        detail::path_traits::dispatch(source, concat_op(*this));
        return *this;
    }

    template< typename Source >
    typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >,
            detail::negation< detail::path_traits::is_path_source< typename std::remove_cv< Source >::type > >
        >::value,
        path&
    >::type concat(Source const& source)
    {
        detail::path_traits::dispatch_convertible(source, concat_op(*this));
        return *this;
    }

    path& concat(path const& p, codecvt_type const&)
    {
        m_pathname.append(p.m_pathname);
        return *this;
    }

    template< typename Source >
    typename std::enable_if<
        detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >::value,
        path&
    >::type concat(Source const& source, codecvt_type const& cvt)
    {
        detail::path_traits::dispatch(source, concat_op(*this), &cvt);
        return *this;
    }

    template< typename Source >
    typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >,
            detail::negation< detail::path_traits::is_path_source< typename std::remove_cv< Source >::type > >
        >::value,
        path&
    >::type concat(Source const& source, codecvt_type const& cvt)
    {
        detail::path_traits::dispatch_convertible(source, concat_op(*this), &cvt);
        return *this;
    }

    path& concat(const value_type* begin, const value_type* end)
    {
        m_pathname.append(begin, end);
        return *this;
    }

    template< typename InputIterator >
    typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_path_source_iterator< InputIterator >,
            detail::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
        >::value,
        path&
    >::type concat(InputIterator begin, InputIterator end)
    {
        if (begin != end)
        {
            std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source(begin, end);
            detail::path_traits::dispatch(source, concat_op(*this));
        }
        return *this;
    }

    path& concat(const value_type* begin, const value_type* end, codecvt_type const&)
    {
        m_pathname.append(begin, end);
        return *this;
    }

    template< typename InputIterator >
    typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_path_source_iterator< InputIterator >,
            detail::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
        >::value,
        path&
    >::type concat(InputIterator begin, InputIterator end, codecvt_type const& cvt)
    {
        if (begin != end)
        {
            std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source(begin, end);
            detail::path_traits::dispatch(source, concat_op(*this), &cvt);
        }
        return *this;
    }

    //  -----  appends  -----

    //  if a separator is added, it is the preferred separator for the platform;
    //  slash for POSIX, backslash for Windows

    path& operator/=(path const& p);

    template< typename Source >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >::value,
        path&
    >::type operator/=(Source const& source)
    {
        return append(source);
    }

    path& append(path const& p);

    template< typename Source >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >::value,
        path&
    >::type append(Source const& source)
    {
        detail::path_traits::dispatch(source, append_op(*this));
        return *this;
    }

    template< typename Source >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >,
            detail::negation< detail::path_traits::is_path_source< typename std::remove_cv< Source >::type > >
        >::value,
        path&
    >::type append(Source const& source)
    {
        detail::path_traits::dispatch_convertible(source, append_op(*this));
        return *this;
    }

    path& append(path const& p, codecvt_type const&);

    template< typename Source >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >::value,
        path&
    >::type append(Source const& source, codecvt_type const& cvt)
    {
        detail::path_traits::dispatch(source, append_op(*this), &cvt);
        return *this;
    }

    template< typename Source >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >,
            detail::negation< detail::path_traits::is_path_source< typename std::remove_cv< Source >::type > >
        >::value,
        path&
    >::type append(Source const& source, codecvt_type const& cvt)
    {
        detail::path_traits::dispatch_convertible(source, append_op(*this), &cvt);
        return *this;
    }

    path& append(const value_type* begin, const value_type* end);

    template< typename InputIterator >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_path_source_iterator< InputIterator >,
            detail::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
        >::value,
        path&
    >::type append(InputIterator begin, InputIterator end)
    {
        std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source(begin, end);
        detail::path_traits::dispatch(source, append_op(*this));
        return *this;
    }

    path& append(const value_type* begin, const value_type* end, codecvt_type const&);

    template< typename InputIterator >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_path_source_iterator< InputIterator >,
            detail::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
        >::value,
        path&
    >::type append(InputIterator begin, InputIterator end, const codecvt_type& cvt)
    {
        std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source(begin, end);
        detail::path_traits::dispatch(source, append_op(*this), &cvt);
        return *this;
    }

    //  -----  modifiers  -----

    void clear() noexcept { m_pathname.clear(); }
    path& make_preferred();
    path& remove_filename();
    BOOST_FILESYSTEM_DECL path& remove_filename_and_trailing_separators();
    BOOST_FILESYSTEM_DECL path& remove_trailing_separator();
    BOOST_FILESYSTEM_DECL path& replace_filename(path const& replacement);
    path& replace_extension(path const& new_extension = path());

    void swap(path& rhs) noexcept { m_pathname.swap(rhs.m_pathname); }

    //  -----  observers  -----

    //  For operating systems that format file paths differently than directory
    //  paths, return values from observers are formatted as file names unless there
    //  is a trailing separator, in which case returns are formatted as directory
    //  paths. POSIX and Windows make no such distinction.

    //  Implementations are permitted to return const values or const references.

    //  The string or path returned by an observer are specified as being formatted
    //  as "native" or "generic".
    //
    //  For POSIX, these are all the same format; slashes and backslashes are as input and
    //  are not modified.
    //
    //  For Windows,   native:    as input; slashes and backslashes are not modified;
    //                            this is the format of the internally stored string.
    //                 generic:   backslashes are converted to slashes

    //  -----  native format observers  -----

    string_type const& native() const noexcept { return m_pathname; }
    const value_type* c_str() const noexcept { return m_pathname.c_str(); }
    string_type::size_type size() const noexcept { return m_pathname.size(); }

    template< typename String >
    String string() const;

    template< typename String >
    String string(codecvt_type const& cvt) const;

#ifdef BOOST_WINDOWS_API
    std::string string() const
    {
        std::string tmp;
        if (!m_pathname.empty())
            detail::path_traits::convert(m_pathname.data(), m_pathname.data() + m_pathname.size(), tmp);
        return tmp;
    }
    std::string string(codecvt_type const& cvt) const
    {
        std::string tmp;
        if (!m_pathname.empty())
            detail::path_traits::convert(m_pathname.data(), m_pathname.data() + m_pathname.size(), tmp, &cvt);
        return tmp;
    }

    //  string_type is std::wstring, so there is no conversion
    std::wstring const& wstring() const { return m_pathname; }
    std::wstring const& wstring(codecvt_type const&) const { return m_pathname; }
#else // BOOST_POSIX_API
    //  string_type is std::string, so there is no conversion
    std::string const& string() const { return m_pathname; }
    std::string const& string(codecvt_type const&) const { return m_pathname; }

    std::wstring wstring() const
    {
        std::wstring tmp;
        if (!m_pathname.empty())
            detail::path_traits::convert(m_pathname.data(), m_pathname.data() + m_pathname.size(), tmp);
        return tmp;
    }
    std::wstring wstring(codecvt_type const& cvt) const
    {
        std::wstring tmp;
        if (!m_pathname.empty())
            detail::path_traits::convert(m_pathname.data(), m_pathname.data() + m_pathname.size(), tmp, &cvt);
        return tmp;
    }
#endif

    //  -----  generic format observers  -----

    //  Experimental generic function returning generic formatted path (i.e. separators
    //  are forward slashes). Motivation: simpler than a family of generic_*string
    //  functions.
    path generic_path() const;

    template< typename String >
    String generic_string() const;

    template< typename String >
    String generic_string(codecvt_type const& cvt) const;

    std::string generic_string() const { return generic_path().string(); }
    std::string generic_string(codecvt_type const& cvt) const { return generic_path().string(cvt); }
    std::wstring generic_wstring() const { return generic_path().wstring(); }
    std::wstring generic_wstring(codecvt_type const& cvt) const { return generic_path().wstring(cvt); }

    //  -----  compare  -----

    int compare(path const& p) const; // generic, lexicographical

    template< typename Source >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >::value,
        int
    >::type compare(Source const& source) const
    {
        return detail::path_traits::dispatch(source, compare_op(*this));
    }

    template< typename Source >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >,
            detail::negation< detail::path_traits::is_path_source< typename std::remove_cv< Source >::type > >
        >::value,
        int
    >::type compare(Source const& source) const
    {
        return detail::path_traits::dispatch_convertible(source, compare_op(*this));
    }

    template< typename Source >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::path_traits::is_path_source< typename std::remove_cv< Source >::type >::value,
        int
    >::type compare(Source const& source, codecvt_type const& cvt) const
    {
        return detail::path_traits::dispatch(source, compare_op(*this), &cvt);
    }

    template< typename Source >
    BOOST_FORCEINLINE typename std::enable_if<
        detail::conjunction<
            detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >,
            detail::negation< detail::path_traits::is_path_source< typename std::remove_cv< Source >::type > >
        >::value,
        int
    >::type compare(Source const& source, codecvt_type const& cvt) const
    {
        return detail::path_traits::dispatch_convertible(source, compare_op(*this), &cvt);
    }

    //  -----  decomposition  -----

    path root_path() const { return path(m_pathname.c_str(), m_pathname.c_str() + detail::path_algorithms::find_root_path_size(*this)); }
    // returns 0 or 1 element path even on POSIX, root_name() is non-empty() for network paths
    path root_name() const { return path(m_pathname.c_str(), m_pathname.c_str() + detail::path_algorithms::find_root_name_size(*this)); }

    // returns 0 or 1 element path
    path root_directory() const
    {
        detail::path_algorithms::substring root_dir = detail::path_algorithms::find_root_directory(*this);
        const value_type* p = m_pathname.c_str() + root_dir.pos;
        return path(p, p + root_dir.size);
    }

    path relative_path() const
    {
        detail::path_algorithms::substring rel_path = detail::path_algorithms::find_relative_path(*this);
        const value_type* p = m_pathname.c_str() + rel_path.pos;
        return path(p, p + rel_path.size);
    }

    path parent_path() const { return path(m_pathname.c_str(), m_pathname.c_str() + detail::path_algorithms::find_parent_path_size(*this)); }

    path filename() const;  // returns 0 or 1 element path
    path stem() const;      // returns 0 or 1 element path
    path extension() const; // returns 0 or 1 element path

    //  -----  query  -----

    bool empty() const noexcept { return m_pathname.empty(); }
    bool filename_is_dot() const;
    bool filename_is_dot_dot() const;
    bool has_root_path() const { return detail::path_algorithms::find_root_path_size(*this) > 0; }
    bool has_root_name() const { return detail::path_algorithms::find_root_name_size(*this) > 0; }
    bool has_root_directory() const { return detail::path_algorithms::find_root_directory(*this).size > 0; }
    bool has_relative_path() const { return detail::path_algorithms::find_relative_path(*this).size > 0; }
    bool has_parent_path() const { return detail::path_algorithms::find_parent_path_size(*this) > 0; }
    bool has_filename() const;
    bool has_stem() const { return !stem().empty(); }
    bool has_extension() const { return !extension().empty(); }
    bool is_relative() const { return !is_absolute(); }
    bool is_absolute() const
    {
#if defined(BOOST_WINDOWS_API)
        return has_root_name() && has_root_directory();
#else
        return has_root_directory();
#endif
    }

    //  -----  lexical operations  -----

    path lexically_normal() const;
    BOOST_FILESYSTEM_DECL path lexically_relative(path const& base) const;
    path lexically_proximate(path const& base) const;

    //  -----  iterators  -----

    BOOST_FILESYSTEM_DECL iterator begin() const;
    BOOST_FILESYSTEM_DECL iterator end() const;
    reverse_iterator rbegin() const;
    reverse_iterator rend() const;

    //  -----  static member functions  -----

    static BOOST_FILESYSTEM_DECL std::locale imbue(std::locale const& loc);
    static BOOST_FILESYSTEM_DECL codecvt_type const& codecvt();

    //--------------------------------------------------------------------------------------//
    //                            class path private members                                //
    //--------------------------------------------------------------------------------------//
private:
    /*
     * m_pathname has the type, encoding, and format required by the native
     * operating system. Thus for POSIX and Windows there is no conversion for
     * passing m_pathname.c_str() to the O/S API or when obtaining a path from the
     * O/S API. POSIX encoding is unspecified other than for dot and slash
     * characters; POSIX just treats paths as a sequence of bytes. Windows
     * encoding is UCS-2 or UTF-16 depending on the version.
     */
    string_type m_pathname;     // Windows: as input; backslashes NOT converted to slashes,
                                // slashes NOT converted to backslashes
};

namespace detail {
BOOST_FILESYSTEM_DECL path const& dot_path();
BOOST_FILESYSTEM_DECL path const& dot_dot_path();
} // namespace detail

namespace path_detail {

//------------------------------------------------------------------------------------//
//                             class path::iterator                                   //
//------------------------------------------------------------------------------------//

class path_iterator :
    public boost::iterator_facade<
        path_iterator,
        const path,
        boost::bidirectional_traversal_tag
    >
{
private:
    friend class boost::iterator_core_access;
    friend class boost::filesystem::path;
    friend class path_reverse_iterator;
    friend struct boost::filesystem::detail::path_algorithms;

    path const& dereference() const { return m_element; }

    bool equal(path_iterator const& rhs) const noexcept
    {
        return m_path_ptr == rhs.m_path_ptr && m_pos == rhs.m_pos;
    }

    void increment();
    void decrement();

private:
    // current element
    path m_element;
    // path being iterated over
    const path* m_path_ptr;
    // position of m_element in m_path_ptr->m_pathname.
    // if m_element is implicit dot, m_pos is the
    // position of the last separator in the path.
    // end() iterator is indicated by
    // m_pos == m_path_ptr->m_pathname.size()
    path::string_type::size_type m_pos;
};

//------------------------------------------------------------------------------------//
//                         class path::reverse_iterator                               //
//------------------------------------------------------------------------------------//

class path_reverse_iterator :
    public boost::iterator_facade<
        path_reverse_iterator,
        const path,
        boost::bidirectional_traversal_tag
    >
{
public:
    explicit path_reverse_iterator(path_iterator itr) :
        m_itr(itr)
    {
        if (itr != itr.m_path_ptr->begin())
            m_element = *--itr;
    }

private:
    friend class boost::iterator_core_access;
    friend class boost::filesystem::path;

    path const& dereference() const { return m_element; }
    bool equal(path_reverse_iterator const& rhs) const noexcept { return m_itr == rhs.m_itr; }

    void increment()
    {
        --m_itr;
        if (m_itr != m_itr.m_path_ptr->begin())
        {
            path_iterator tmp = m_itr;
            m_element = *--tmp;
        }
    }

    void decrement()
    {
        m_element = *m_itr;
        ++m_itr;
    }

private:
    path_iterator m_itr;
    path m_element;
};

//  std::lexicographical_compare would infinitely recurse because path iterators
//  yield paths, so provide a path aware version
bool lexicographical_compare(path_iterator first1, path_iterator const& last1, path_iterator first2, path_iterator const& last2);

} // namespace path_detail

using path_detail::lexicographical_compare;

//------------------------------------------------------------------------------------//
//                                                                                    //
//                              non-member functions                                  //
//                                                                                    //
//------------------------------------------------------------------------------------//

BOOST_FORCEINLINE bool operator==(path const& lhs, path const& rhs)
{
    return lhs.compare(rhs) == 0;
}

template< typename Path, typename Source >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator==(Path const& lhs, Source const& rhs)
{
    return lhs.compare(rhs) == 0;
}

template< typename Source, typename Path >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator==(Source const& lhs, Path const& rhs)
{
    return rhs.compare(lhs) == 0;
}

BOOST_FORCEINLINE bool operator!=(path const& lhs, path const& rhs)
{
    return lhs.compare(rhs) != 0;
}

template< typename Path, typename Source >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator!=(Path const& lhs, Source const& rhs)
{
    return lhs.compare(rhs) != 0;
}

template< typename Source, typename Path >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator!=(Source const& lhs, Path const& rhs)
{
    return rhs.compare(lhs) != 0;
}

BOOST_FORCEINLINE bool operator<(path const& lhs, path const& rhs)
{
    return lhs.compare(rhs) < 0;
}

template< typename Path, typename Source >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator<(Path const& lhs, Source const& rhs)
{
    return lhs.compare(rhs) < 0;
}

template< typename Source, typename Path >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator<(Source const& lhs, Path const& rhs)
{
    return rhs.compare(lhs) > 0;
}

BOOST_FORCEINLINE bool operator<=(path const& lhs, path const& rhs)
{
    return lhs.compare(rhs) <= 0;
}

template< typename Path, typename Source >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator<=(Path const& lhs, Source const& rhs)
{
    return lhs.compare(rhs) <= 0;
}

template< typename Source, typename Path >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator<=(Source const& lhs, Path const& rhs)
{
    return rhs.compare(lhs) >= 0;
}

BOOST_FORCEINLINE bool operator>(path const& lhs, path const& rhs)
{
    return lhs.compare(rhs) > 0;
}

template< typename Path, typename Source >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator>(Path const& lhs, Source const& rhs)
{
    return lhs.compare(rhs) > 0;
}

template< typename Source, typename Path >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator>(Source const& lhs, Path const& rhs)
{
    return rhs.compare(lhs) < 0;
}

BOOST_FORCEINLINE bool operator>=(path const& lhs, path const& rhs)
{
    return lhs.compare(rhs) >= 0;
}

template< typename Path, typename Source >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator>=(Path const& lhs, Source const& rhs)
{
    return lhs.compare(rhs) >= 0;
}

template< typename Source, typename Path >
BOOST_FORCEINLINE typename std::enable_if<
    detail::conjunction<
        std::is_same< Path, path >,
        detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >
    >::value,
    bool
>::type operator>=(Source const& lhs, Path const& rhs)
{
    return rhs.compare(lhs) <= 0;
}


// Note: Declared as a template to delay binding to Boost.ContainerHash functions and make the dependency optional
template< typename Path >
inline typename std::enable_if<
    std::is_same< Path, path >::value,
    std::size_t
>::type hash_value(Path const& p) noexcept
{
#ifdef BOOST_WINDOWS_API
    std::size_t seed = 0u;
    for (typename Path::value_type const* it = p.c_str(); *it; ++it)
        hash_combine(seed, *it == L'/' ? L'\\' : *it);
    return seed;
#else // BOOST_POSIX_API
    return hash_range(p.native().begin(), p.native().end());
#endif
}

inline void swap(path& lhs, path& rhs) noexcept
{
    lhs.swap(rhs);
}

BOOST_FORCEINLINE path operator/(path lhs, path const& rhs)
{
    lhs.append(rhs);
    return lhs;
}

template< typename Source >
BOOST_FORCEINLINE typename std::enable_if<
    detail::path_traits::is_convertible_to_path_source< typename std::remove_cv< Source >::type >::value,
    path
>::type operator/(path lhs, Source const& rhs)
{
    lhs.append(rhs);
    return lhs;
}

//  inserters and extractors
//    use boost::io::quoted() to handle spaces in paths
//    use '&' as escape character to ease use for Windows paths

template< typename Char, typename Traits >
inline std::basic_ostream< Char, Traits >&
operator<<(std::basic_ostream< Char, Traits >& os, path const& p)
{
    return os << boost::io::quoted(p.template string< std::basic_string< Char > >(), static_cast< Char >('&'));
}

template< typename Char, typename Traits >
inline std::basic_istream< Char, Traits >&
operator>>(std::basic_istream< Char, Traits >& is, path& p)
{
    std::basic_string< Char > str;
    is >> boost::io::quoted(str, static_cast< Char >('&'));
    p = str;
    return is;
}

//  name_checks

//  These functions are holdovers from version 1. It isn't clear they have much
//  usefulness, or how to generalize them for later versions.

BOOST_FILESYSTEM_DECL bool portable_posix_name(std::string const& name);
BOOST_FILESYSTEM_DECL bool windows_name(std::string const& name);
BOOST_FILESYSTEM_DECL bool portable_name(std::string const& name);
BOOST_FILESYSTEM_DECL bool portable_directory_name(std::string const& name);
BOOST_FILESYSTEM_DECL bool portable_file_name(std::string const& name);
BOOST_FILESYSTEM_DECL bool native(std::string const& name);

namespace detail {

//  For POSIX, is_directory_separator() and is_element_separator() are identical since
//  a forward slash is the only valid directory separator and also the only valid
//  element separator. For Windows, forward slash and back slash are the possible
//  directory separators, but colon (example: "c:foo") is also an element separator.
inline bool is_directory_separator(path::value_type c) noexcept
{
    return c == path::separator
#ifdef BOOST_WINDOWS_API
        || c == path::preferred_separator
#endif
        ;
}

inline bool is_element_separator(path::value_type c) noexcept
{
    return c == path::separator
#ifdef BOOST_WINDOWS_API
        || c == path::preferred_separator || c == L':'
#endif
        ;
}

} // namespace detail

//------------------------------------------------------------------------------------//
//                  class path miscellaneous function implementations                 //
//------------------------------------------------------------------------------------//

namespace detail {

inline bool path_algorithms::has_filename_v3(path const& p)
{
    return !p.m_pathname.empty();
}

inline bool path_algorithms::has_filename_v4(path const& p)
{
    return path_algorithms::find_filename_v4_size(p) > 0;
}

inline path path_algorithms::filename_v4(path const& p)
{
    string_type::size_type filename_size = path_algorithms::find_filename_v4_size(p);
    string_type::size_type pos = p.m_pathname.size() - filename_size;
    const value_type* ptr = p.m_pathname.c_str() + pos;
    return path(ptr, ptr + filename_size);
}

inline path path_algorithms::extension_v4(path const& p)
{
    string_type::size_type extension_size = path_algorithms::find_extension_v4_size(p);
    string_type::size_type pos = p.m_pathname.size() - extension_size;
    const value_type* ptr = p.m_pathname.c_str() + pos;
    return path(ptr, ptr + extension_size);
}

inline void path_algorithms::append_v4(path& left, path const& right)
{
    path_algorithms::append_v4(left, right.m_pathname.c_str(), right.m_pathname.c_str() + right.m_pathname.size());
}

} // namespace detail

// Note: Because of the range constructor in C++23 std::string_view that involves a check for contiguous_range concept,
//       any non-template function call that requires a check whether the source argument (which may be fs::path)
//       is convertible to std::string_view must be made after fs::path::iterator is defined. This includes overload
//       resolution and SFINAE checks. Otherwise, the concept check result formally changes between fs::path::iterator
//       is not defined and defined, which causes compilation errors with gcc 11 and later.
//       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106808

BOOST_FORCEINLINE path::compare_op::result_type path::compare_op::operator() (const value_type* source, const value_type* source_end, const codecvt_type*) const
{
    path src;
    src.m_pathname.assign(source, source_end);
    return m_self.compare(src);
}

template< typename OtherChar >
BOOST_FORCEINLINE path::compare_op::result_type path::compare_op::operator() (const OtherChar* source, const OtherChar* source_end, const codecvt_type* cvt) const
{
    path src;
    detail::path_traits::convert(source, source_end, src.m_pathname, cvt);
    return m_self.compare(src);
}

inline path& path::operator=(path const& p)
{
    return assign(p);
}

inline path& path::operator+=(path const& p)
{
    return concat(p);
}

BOOST_FORCEINLINE path& path::operator/=(path const& p)
{
    return append(p);
}

inline path path::lexically_proximate(path const& base) const
{
    path tmp(lexically_relative(base));
    return tmp.empty() ? *this : tmp;
}

inline path::reverse_iterator path::rbegin() const
{
    return reverse_iterator(end());
}

inline path::reverse_iterator path::rend() const
{
    return reverse_iterator(begin());
}

inline bool path::filename_is_dot() const
{
    // implicit dot is tricky, so actually call filename(); see path::filename() example
    // in reference.html
    path p(filename());
    return p.size() == 1 && *p.c_str() == dot;
}

inline bool path::filename_is_dot_dot() const
{
    return size() >= 2 && m_pathname[size() - 1] == dot && m_pathname[size() - 2] == dot && (m_pathname.size() == 2 || detail::is_element_separator(m_pathname[size() - 3]));
    // use detail::is_element_separator() rather than detail::is_directory_separator
    // to deal with "c:.." edge case on Windows when ':' acts as a separator
}

// The following functions are defined differently, depending on Boost.Filesystem version in use.
// To avoid ODR violation, these functions are not defined when the library itself is built.
// This makes sure they are not compiled when the library is built, and the only version there is
// is the one in user's code. Users are supposed to consistently use the same Boost.Filesystem version
// in all their translation units.
#if !defined(BOOST_FILESYSTEM_SOURCE)

BOOST_FORCEINLINE path& path::append(path const& p)
{
    BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::append)(*this, p.m_pathname.data(), p.m_pathname.data() + p.m_pathname.size());
    return *this;
}

BOOST_FORCEINLINE path& path::append(path const& p, codecvt_type const&)
{
    BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::append)(*this, p.m_pathname.data(), p.m_pathname.data() + p.m_pathname.size());
    return *this;
}

BOOST_FORCEINLINE path& path::append(const value_type* begin, const value_type* end)
{
    BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::append)(*this, begin, end);
    return *this;
}

BOOST_FORCEINLINE path& path::append(const value_type* begin, const value_type* end, codecvt_type const&)
{
    BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::append)(*this, begin, end);
    return *this;
}

BOOST_FORCEINLINE path& path::remove_filename()
{
    BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::remove_filename)(*this);
    return *this;
}

BOOST_FORCEINLINE path& path::replace_extension(path const& new_extension)
{
    BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::replace_extension)(*this, new_extension);
    return *this;
}

BOOST_FORCEINLINE int path::compare(path const& p) const
{
    return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::compare)(*this, p);
}

BOOST_FORCEINLINE path path::filename() const
{
    return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::filename)(*this);
}

BOOST_FORCEINLINE path path::stem() const
{
    return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::stem)(*this);
}

BOOST_FORCEINLINE path path::extension() const
{
    return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::extension)(*this);
}

BOOST_FORCEINLINE bool path::has_filename() const
{
    return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::has_filename)(*this);
}

BOOST_FORCEINLINE path path::lexically_normal() const
{
    return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::lexically_normal)(*this);
}

BOOST_FORCEINLINE path path::generic_path() const
{
    return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::generic_path)(*this);
}

BOOST_FORCEINLINE path& path::make_preferred()
{
    // No effect on POSIX
#if defined(BOOST_WINDOWS_API)
    BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::make_preferred)(*this);
#endif
    return *this;
}

namespace path_detail {

BOOST_FORCEINLINE void path_iterator::increment()
{
    BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::increment)(*this);
}

BOOST_FORCEINLINE void path_iterator::decrement()
{
    BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::decrement)(*this);
}

BOOST_FORCEINLINE bool lexicographical_compare(path_iterator first1, path_iterator const& last1, path_iterator first2, path_iterator const& last2)
{
    return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::lex_compare)(first1, last1, first2, last2) < 0;
}

} // namespace path_detail

#endif // !defined(BOOST_FILESYSTEM_SOURCE)

//--------------------------------------------------------------------------------------//
//                     class path member template specializations                       //
//--------------------------------------------------------------------------------------//

template< >
inline std::string path::string< std::string >() const
{
    return string();
}

template< >
inline std::wstring path::string< std::wstring >() const
{
    return wstring();
}

template< >
inline std::string path::string< std::string >(codecvt_type const& cvt) const
{
    return string(cvt);
}

template< >
inline std::wstring path::string< std::wstring >(codecvt_type const& cvt) const
{
    return wstring(cvt);
}

template< >
inline std::string path::generic_string< std::string >() const
{
    return generic_string();
}

template< >
inline std::wstring path::generic_string< std::wstring >() const
{
    return generic_wstring();
}

template< >
inline std::string path::generic_string< std::string >(codecvt_type const& cvt) const
{
    return generic_string(cvt);
}

template< >
inline std::wstring path::generic_string< std::wstring >(codecvt_type const& cvt) const
{
    return generic_wstring(cvt);
}

} // namespace filesystem
} // namespace boost

//----------------------------------------------------------------------------//

#include <boost/filesystem/detail/footer.hpp>

#endif // BOOST_FILESYSTEM_PATH_HPP