path.hpp 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800
  1. // filesystem path.hpp ---------------------------------------------------------------//
  2. // Copyright Vladimir Prus 2002
  3. // Copyright Beman Dawes 2002-2005, 2009
  4. // Copyright Andrey Semashev 2021-2023
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // See http://www.boost.org/LICENSE_1_0.txt
  7. // Library home page: http://www.boost.org/libs/filesystem
  8. // path::stem(), extension(), and replace_extension() are based on
  9. // basename(), extension(), and change_extension() from the original
  10. // filesystem/convenience.hpp header by Vladimir Prus.
  11. #ifndef BOOST_FILESYSTEM_PATH_HPP
  12. #define BOOST_FILESYSTEM_PATH_HPP
  13. #include <boost/assert.hpp>
  14. #include <boost/filesystem/config.hpp>
  15. #include <boost/filesystem/detail/path_traits.hpp>
  16. #include <boost/iterator/iterator_facade.hpp>
  17. #include <boost/iterator/iterator_categories.hpp>
  18. #include <boost/core/enable_if.hpp>
  19. #include <boost/io/quoted.hpp>
  20. #include <boost/functional/hash_fwd.hpp>
  21. #include <boost/type_traits/negation.hpp>
  22. #include <boost/type_traits/conjunction.hpp>
  23. #include <boost/type_traits/disjunction.hpp>
  24. #include <boost/type_traits/is_same.hpp>
  25. #include <boost/type_traits/remove_cv.hpp>
  26. #include <cstddef>
  27. #include <iosfwd>
  28. #include <locale>
  29. #include <string>
  30. #include <iterator>
  31. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  32. #include <string_view>
  33. #endif
  34. #include <boost/filesystem/detail/header.hpp> // must be the last #include
  35. namespace boost {
  36. namespace filesystem {
  37. class path;
  38. namespace path_detail { // intentionally don't use filesystem::detail to not bring internal Boost.Filesystem functions into ADL via path_constants
  39. template< typename Char, Char Separator, Char PreferredSeparator, Char Dot >
  40. struct path_constants
  41. {
  42. typedef path_constants< Char, Separator, PreferredSeparator, Dot > path_constants_base;
  43. typedef Char value_type;
  44. static BOOST_CONSTEXPR_OR_CONST value_type separator = Separator;
  45. static BOOST_CONSTEXPR_OR_CONST value_type preferred_separator = PreferredSeparator;
  46. static BOOST_CONSTEXPR_OR_CONST value_type dot = Dot;
  47. };
  48. #if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
  49. template< typename Char, Char Separator, Char PreferredSeparator, Char Dot >
  50. BOOST_CONSTEXPR_OR_CONST typename path_constants< Char, Separator, PreferredSeparator, Dot >::value_type
  51. path_constants< Char, Separator, PreferredSeparator, Dot >::separator;
  52. template< typename Char, Char Separator, Char PreferredSeparator, Char Dot >
  53. BOOST_CONSTEXPR_OR_CONST typename path_constants< Char, Separator, PreferredSeparator, Dot >::value_type
  54. path_constants< Char, Separator, PreferredSeparator, Dot >::preferred_separator;
  55. template< typename Char, Char Separator, Char PreferredSeparator, Char Dot >
  56. BOOST_CONSTEXPR_OR_CONST typename path_constants< Char, Separator, PreferredSeparator, Dot >::value_type
  57. path_constants< Char, Separator, PreferredSeparator, Dot >::dot;
  58. #endif
  59. class path_iterator;
  60. class path_reverse_iterator;
  61. } // namespace path_detail
  62. namespace detail {
  63. struct path_algorithms
  64. {
  65. // A struct that denotes a contiguous range of characters in a string. A lightweight alternative to string_view.
  66. struct substring
  67. {
  68. std::size_t pos;
  69. std::size_t size;
  70. };
  71. typedef path_traits::path_native_char_type value_type;
  72. typedef std::basic_string< value_type > string_type;
  73. static bool has_filename_v3(path const& p);
  74. static bool has_filename_v4(path const& p);
  75. BOOST_FILESYSTEM_DECL static path filename_v3(path const& p);
  76. static path filename_v4(path const& p);
  77. BOOST_FILESYSTEM_DECL static path stem_v3(path const& p);
  78. BOOST_FILESYSTEM_DECL static path stem_v4(path const& p);
  79. BOOST_FILESYSTEM_DECL static path extension_v3(path const& p);
  80. static path extension_v4(path const& p);
  81. BOOST_FILESYSTEM_DECL static void remove_filename_v3(path& p);
  82. BOOST_FILESYSTEM_DECL static void remove_filename_v4(path& p);
  83. BOOST_FILESYSTEM_DECL static void replace_extension_v3(path& p, path const& new_extension);
  84. BOOST_FILESYSTEM_DECL static void replace_extension_v4(path& p, path const& new_extension);
  85. BOOST_FILESYSTEM_DECL static path lexically_normal_v3(path const& p);
  86. BOOST_FILESYSTEM_DECL static path lexically_normal_v4(path const& p);
  87. BOOST_FILESYSTEM_DECL static int compare_v3(path const& left, path const& right);
  88. BOOST_FILESYSTEM_DECL static int compare_v4(path const& left, path const& right);
  89. BOOST_FILESYSTEM_DECL static void append_v3(path& p, const value_type* b, const value_type* e);
  90. BOOST_FILESYSTEM_DECL static void append_v4(path& p, const value_type* b, const value_type* e);
  91. static void append_v4(path& left, path const& right);
  92. // Returns: If separator is to be appended, m_pathname.size() before append. Otherwise 0.
  93. // Note: An append is never performed if size()==0, so a returned 0 is unambiguous.
  94. BOOST_FILESYSTEM_DECL static string_type::size_type append_separator_if_needed(path& p);
  95. BOOST_FILESYSTEM_DECL static void erase_redundant_separator(path& p, string_type::size_type sep_pos);
  96. BOOST_FILESYSTEM_DECL static string_type::size_type find_root_name_size(path const& p);
  97. BOOST_FILESYSTEM_DECL static string_type::size_type find_root_path_size(path const& p);
  98. BOOST_FILESYSTEM_DECL static substring find_root_directory(path const& p);
  99. BOOST_FILESYSTEM_DECL static substring find_relative_path(path const& p);
  100. BOOST_FILESYSTEM_DECL static string_type::size_type find_parent_path_size(path const& p);
  101. BOOST_FILESYSTEM_DECL static string_type::size_type find_filename_v4_size(path const& p);
  102. BOOST_FILESYSTEM_DECL static string_type::size_type find_extension_v4_size(path const& p);
  103. BOOST_FILESYSTEM_DECL static int lex_compare_v3
  104. (
  105. path_detail::path_iterator first1, path_detail::path_iterator const& last1,
  106. path_detail::path_iterator first2, path_detail::path_iterator const& last2
  107. );
  108. BOOST_FILESYSTEM_DECL static int lex_compare_v4
  109. (
  110. path_detail::path_iterator first1, path_detail::path_iterator const& last1,
  111. path_detail::path_iterator first2, path_detail::path_iterator const& last2
  112. );
  113. BOOST_FILESYSTEM_DECL static void increment_v3(path_detail::path_iterator& it);
  114. BOOST_FILESYSTEM_DECL static void increment_v4(path_detail::path_iterator& it);
  115. BOOST_FILESYSTEM_DECL static void decrement_v3(path_detail::path_iterator& it);
  116. BOOST_FILESYSTEM_DECL static void decrement_v4(path_detail::path_iterator& it);
  117. };
  118. } // namespace detail
  119. //------------------------------------------------------------------------------------//
  120. // //
  121. // class path //
  122. // //
  123. //------------------------------------------------------------------------------------//
  124. class path :
  125. public filesystem::path_detail::path_constants<
  126. #ifdef BOOST_WINDOWS_API
  127. detail::path_traits::path_native_char_type, L'/', L'\\', L'.'
  128. #else
  129. detail::path_traits::path_native_char_type, '/', '/', '.'
  130. #endif
  131. >
  132. {
  133. friend class path_detail::path_iterator;
  134. friend class path_detail::path_reverse_iterator;
  135. friend struct detail::path_algorithms;
  136. public:
  137. // value_type is the character type used by the operating system API to
  138. // represent paths.
  139. typedef detail::path_algorithms::value_type value_type;
  140. typedef detail::path_algorithms::string_type string_type;
  141. typedef detail::path_traits::codecvt_type codecvt_type;
  142. // ----- character encoding conversions -----
  143. // Following the principle of least astonishment, path input arguments
  144. // passed to or obtained from the operating system via objects of
  145. // class path behave as if they were directly passed to or
  146. // obtained from the O/S API, unless conversion is explicitly requested.
  147. //
  148. // POSIX specfies that path strings are passed unchanged to and from the
  149. // API. Note that this is different from the POSIX command line utilities,
  150. // which convert according to a locale.
  151. //
  152. // Thus for POSIX, char strings do not undergo conversion. wchar_t strings
  153. // are converted to/from char using the path locale or, if a conversion
  154. // argument is given, using a conversion object modeled on
  155. // std::wstring_convert.
  156. //
  157. // The path locale, which is global to the thread, can be changed by the
  158. // imbue() function. It is initialized to an implementation defined locale.
  159. //
  160. // For Windows, wchar_t strings do not undergo conversion. char strings
  161. // are converted using the "ANSI" or "OEM" code pages, as determined by
  162. // the AreFileApisANSI() function, or, if a conversion argument is given,
  163. // using a conversion object modeled on std::wstring_convert.
  164. //
  165. // See m_pathname comments for further important rationale.
  166. // TODO: rules needed for operating systems that use / or .
  167. // differently, or format directory paths differently from file paths.
  168. //
  169. // **********************************************************************************
  170. //
  171. // More work needed: How to handle an operating system that may have
  172. // slash characters or dot characters in valid filenames, either because
  173. // it doesn't follow the POSIX standard, or because it allows MBCS
  174. // filename encodings that may contain slash or dot characters. For
  175. // example, ISO/IEC 2022 (JIS) encoding which allows switching to
  176. // JIS x0208-1983 encoding. A valid filename in this set of encodings is
  177. // 0x1B 0x24 0x42 [switch to X0208-1983] 0x24 0x2F [U+304F Kiragana letter KU]
  178. // ^^^^
  179. // Note that 0x2F is the ASCII slash character
  180. //
  181. // **********************************************************************************
  182. // Supported source arguments: half-open iterator range, container, c-array,
  183. // and single pointer to null terminated string.
  184. // All source arguments except pointers to null terminated byte strings support
  185. // multi-byte character strings which may have embedded nulls. Embedded null
  186. // support is required for some Asian languages on Windows.
  187. // "const codecvt_type& cvt=codecvt()" default arguments are not used because this
  188. // limits the impact of locale("") initialization failures on POSIX systems to programs
  189. // that actually depend on locale(""). It further ensures that exceptions thrown
  190. // as a result of such failues occur after main() has started, so can be caught.
  191. private:
  192. //! Assignment operation
  193. class assign_op
  194. {
  195. private:
  196. path& m_self;
  197. public:
  198. typedef void result_type;
  199. explicit assign_op(path& self) BOOST_NOEXCEPT : m_self(self) {}
  200. result_type operator() (const value_type* source, const value_type* source_end, const codecvt_type* = NULL) const
  201. {
  202. m_self.m_pathname.assign(source, source_end);
  203. }
  204. template< typename OtherChar >
  205. result_type operator() (const OtherChar* source, const OtherChar* source_end, const codecvt_type* cvt = NULL) const
  206. {
  207. m_self.m_pathname.clear();
  208. detail::path_traits::convert(source, source_end, m_self.m_pathname, cvt);
  209. }
  210. };
  211. //! Concatenation operation
  212. class concat_op
  213. {
  214. private:
  215. path& m_self;
  216. public:
  217. typedef void result_type;
  218. explicit concat_op(path& self) BOOST_NOEXCEPT : m_self(self) {}
  219. result_type operator() (const value_type* source, const value_type* source_end, const codecvt_type* = NULL) const
  220. {
  221. m_self.m_pathname.append(source, source_end);
  222. }
  223. template< typename OtherChar >
  224. result_type operator() (const OtherChar* source, const OtherChar* source_end, const codecvt_type* cvt = NULL) const
  225. {
  226. detail::path_traits::convert(source, source_end, m_self.m_pathname, cvt);
  227. }
  228. };
  229. //! Path appending operation
  230. class append_op
  231. {
  232. private:
  233. path& m_self;
  234. public:
  235. typedef void result_type;
  236. explicit append_op(path& self) BOOST_NOEXCEPT : m_self(self) {}
  237. BOOST_FORCEINLINE result_type operator() (const value_type* source, const value_type* source_end, const codecvt_type* = NULL) const
  238. {
  239. m_self.append(source, source_end);
  240. }
  241. template< typename OtherChar >
  242. BOOST_FORCEINLINE result_type operator() (const OtherChar* source, const OtherChar* source_end, const codecvt_type* cvt = NULL) const
  243. {
  244. string_type src;
  245. detail::path_traits::convert(source, source_end, src, cvt);
  246. m_self.append(src.data(), src.data() + src.size());
  247. }
  248. };
  249. //! Path comparison operation
  250. class compare_op
  251. {
  252. private:
  253. path const& m_self;
  254. public:
  255. typedef int result_type;
  256. explicit compare_op(path const& self) BOOST_NOEXCEPT : m_self(self) {}
  257. result_type operator() (const value_type* source, const value_type* source_end, const codecvt_type* = NULL) const;
  258. template< typename OtherChar >
  259. result_type operator() (const OtherChar* source, const OtherChar* source_end, const codecvt_type* cvt = NULL) const;
  260. };
  261. public:
  262. typedef path_detail::path_iterator iterator;
  263. typedef iterator const_iterator;
  264. typedef path_detail::path_reverse_iterator reverse_iterator;
  265. typedef reverse_iterator const_reverse_iterator;
  266. public:
  267. // ----- constructors -----
  268. path() BOOST_NOEXCEPT {}
  269. path(path const& p) : m_pathname(p.m_pathname) {}
  270. path(path const& p, codecvt_type const&) : m_pathname(p.m_pathname) {}
  271. path(const value_type* s) : m_pathname(s) {}
  272. path(const value_type* s, codecvt_type const&) : m_pathname(s) {}
  273. path(string_type const& s) : m_pathname(s) {}
  274. path(string_type const& s, codecvt_type const&) : m_pathname(s) {}
  275. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  276. path(std::basic_string_view< value_type > const& s) : m_pathname(s) {}
  277. path(std::basic_string_view< value_type > const& s, codecvt_type const&) : m_pathname(s) {}
  278. #endif
  279. #if !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
  280. template<
  281. typename Source,
  282. typename = typename boost::enable_if_c<
  283. boost::conjunction<
  284. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >,
  285. boost::negation< detail::path_traits::is_native_path_source< typename boost::remove_cv< Source >::type > >
  286. >::value
  287. >::type
  288. >
  289. path(Source const& source)
  290. #else
  291. template< typename Source >
  292. path(Source const& source, typename boost::enable_if_c<
  293. boost::conjunction<
  294. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >,
  295. boost::negation< detail::path_traits::is_native_path_source< typename boost::remove_cv< Source >::type > >
  296. >::value
  297. >::type* = NULL)
  298. #endif
  299. {
  300. assign(source);
  301. }
  302. #if !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
  303. template<
  304. typename Source,
  305. typename = typename boost::enable_if_c<
  306. boost::conjunction<
  307. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >,
  308. boost::negation< detail::path_traits::is_native_path_source< typename boost::remove_cv< Source >::type > >
  309. >::value
  310. >::type
  311. >
  312. explicit path(Source const& source, codecvt_type const& cvt)
  313. #else
  314. template< typename Source >
  315. explicit path(Source const& source, codecvt_type const& cvt, typename boost::enable_if_c<
  316. boost::conjunction<
  317. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >,
  318. boost::negation< detail::path_traits::is_native_path_source< typename boost::remove_cv< Source >::type > >
  319. >::value
  320. >::type* = NULL)
  321. #endif
  322. {
  323. assign(source, cvt);
  324. }
  325. // As of October 2015 the interaction between noexcept and =default is so troublesome
  326. // for VC++, GCC, and probably other compilers, that =default is not used with noexcept
  327. // functions. GCC is not even consistent for the same release on different platforms.
  328. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  329. path(path&& p) BOOST_NOEXCEPT : m_pathname(static_cast< string_type&& >(p.m_pathname))
  330. {
  331. }
  332. path(path&& p, codecvt_type const&) BOOST_NOEXCEPT : m_pathname(static_cast< string_type&& >(p.m_pathname))
  333. {
  334. }
  335. path& operator=(path&& p) BOOST_NOEXCEPT
  336. {
  337. m_pathname = static_cast< string_type&& >(p.m_pathname);
  338. return *this;
  339. }
  340. path& assign(path&& p) BOOST_NOEXCEPT
  341. {
  342. m_pathname = static_cast< string_type&& >(p.m_pathname);
  343. return *this;
  344. }
  345. path& assign(path&& p, codecvt_type const&) BOOST_NOEXCEPT
  346. {
  347. m_pathname = static_cast< string_type&& >(p.m_pathname);
  348. return *this;
  349. }
  350. path(string_type&& s) BOOST_NOEXCEPT : m_pathname(static_cast< string_type&& >(s))
  351. {
  352. }
  353. path(string_type&& s, codecvt_type const&) BOOST_NOEXCEPT : m_pathname(static_cast< string_type&& >(s))
  354. {
  355. }
  356. path& operator=(string_type&& p) BOOST_NOEXCEPT
  357. {
  358. m_pathname = static_cast< string_type&& >(p);
  359. return *this;
  360. }
  361. path& assign(string_type&& p) BOOST_NOEXCEPT
  362. {
  363. m_pathname = static_cast< string_type&& >(p);
  364. return *this;
  365. }
  366. path& assign(string_type&& p, codecvt_type const&) BOOST_NOEXCEPT
  367. {
  368. m_pathname = static_cast< string_type&& >(p);
  369. return *this;
  370. }
  371. #endif
  372. path(const value_type* begin, const value_type* end) : m_pathname(begin, end) {}
  373. path(const value_type* begin, const value_type* end, codecvt_type const&) : m_pathname(begin, end) {}
  374. #if !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
  375. template<
  376. typename InputIterator,
  377. typename = typename boost::enable_if_c<
  378. boost::conjunction<
  379. detail::path_traits::is_path_source_iterator< InputIterator >,
  380. boost::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
  381. >::value
  382. >::type
  383. >
  384. path(InputIterator begin, InputIterator end)
  385. #else
  386. template< typename InputIterator >
  387. path(InputIterator begin, InputIterator end, typename boost::enable_if_c<
  388. boost::conjunction<
  389. detail::path_traits::is_path_source_iterator< InputIterator >,
  390. boost::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
  391. >::value
  392. >::type* = NULL)
  393. #endif
  394. {
  395. if (begin != end)
  396. {
  397. typedef std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source_t;
  398. source_t source(begin, end);
  399. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  400. assign(static_cast< source_t&& >(source));
  401. #else
  402. assign(source);
  403. #endif
  404. }
  405. }
  406. #if !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
  407. template<
  408. typename InputIterator,
  409. typename = typename boost::enable_if_c<
  410. boost::conjunction<
  411. detail::path_traits::is_path_source_iterator< InputIterator >,
  412. boost::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
  413. >::value
  414. >::type
  415. >
  416. path(InputIterator begin, InputIterator end, codecvt_type const& cvt)
  417. #else
  418. template< typename InputIterator >
  419. path(InputIterator begin, InputIterator end, codecvt_type const& cvt, typename boost::enable_if_c<
  420. boost::conjunction<
  421. detail::path_traits::is_path_source_iterator< InputIterator >,
  422. boost::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
  423. >::value
  424. >::type* = NULL)
  425. #endif
  426. {
  427. if (begin != end)
  428. {
  429. typedef std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source_t;
  430. source_t source(begin, end);
  431. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  432. assign(static_cast< source_t&& >(source), cvt);
  433. #else
  434. assign(source, cvt);
  435. #endif
  436. }
  437. }
  438. #if !defined(BOOST_NO_CXX11_NULLPTR)
  439. BOOST_DELETED_FUNCTION(path(std::nullptr_t))
  440. BOOST_DELETED_FUNCTION(path& operator= (std::nullptr_t))
  441. #endif
  442. public:
  443. // ----- assignments -----
  444. // We need to explicitly define copy assignment as otherwise it will be implicitly defined as deleted because there is move assignment
  445. path& operator=(path const& p);
  446. template< typename Source >
  447. typename boost::enable_if_c<
  448. boost::disjunction<
  449. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >,
  450. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >
  451. >::value,
  452. path&
  453. >::type operator=(Source const& source)
  454. {
  455. return assign(source);
  456. }
  457. path& assign(path const& p)
  458. {
  459. m_pathname = p.m_pathname;
  460. return *this;
  461. }
  462. template< typename Source >
  463. typename boost::enable_if_c<
  464. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >::value,
  465. path&
  466. >::type assign(Source const& source)
  467. {
  468. detail::path_traits::dispatch(source, assign_op(*this));
  469. return *this;
  470. }
  471. template< typename Source >
  472. typename boost::enable_if_c<
  473. boost::conjunction<
  474. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >,
  475. boost::negation< detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type > >
  476. >::value,
  477. path&
  478. >::type assign(Source const& source)
  479. {
  480. detail::path_traits::dispatch_convertible(source, assign_op(*this));
  481. return *this;
  482. }
  483. path& assign(path const& p, codecvt_type const&)
  484. {
  485. m_pathname = p.m_pathname;
  486. return *this;
  487. }
  488. template< typename Source >
  489. typename boost::enable_if_c<
  490. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >::value,
  491. path&
  492. >::type assign(Source const& source, codecvt_type const& cvt)
  493. {
  494. detail::path_traits::dispatch(source, assign_op(*this), &cvt);
  495. return *this;
  496. }
  497. template< typename Source >
  498. typename boost::enable_if_c<
  499. boost::conjunction<
  500. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >,
  501. boost::negation< detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type > >
  502. >::value,
  503. path&
  504. >::type assign(Source const& source, codecvt_type const& cvt)
  505. {
  506. detail::path_traits::dispatch_convertible(source, assign_op(*this), &cvt);
  507. return *this;
  508. }
  509. path& assign(const value_type* begin, const value_type* end)
  510. {
  511. m_pathname.assign(begin, end);
  512. return *this;
  513. }
  514. template< typename InputIterator >
  515. typename boost::enable_if_c<
  516. boost::conjunction<
  517. detail::path_traits::is_path_source_iterator< InputIterator >,
  518. boost::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
  519. >::value,
  520. path&
  521. >::type assign(InputIterator begin, InputIterator end)
  522. {
  523. m_pathname.clear();
  524. if (begin != end)
  525. {
  526. typedef std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source_t;
  527. source_t source(begin, end);
  528. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  529. assign(static_cast< source_t&& >(source));
  530. #else
  531. assign(source);
  532. #endif
  533. }
  534. return *this;
  535. }
  536. path& assign(const value_type* begin, const value_type* end, codecvt_type const&)
  537. {
  538. m_pathname.assign(begin, end);
  539. return *this;
  540. }
  541. template< typename InputIterator >
  542. typename boost::enable_if_c<
  543. boost::conjunction<
  544. detail::path_traits::is_path_source_iterator< InputIterator >,
  545. boost::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
  546. >::value,
  547. path&
  548. >::type assign(InputIterator begin, InputIterator end, codecvt_type const& cvt)
  549. {
  550. m_pathname.clear();
  551. if (begin != end)
  552. {
  553. typedef std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source_t;
  554. source_t source(begin, end);
  555. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  556. assign(static_cast< source_t&& >(source), cvt);
  557. #else
  558. assign(source, cvt);
  559. #endif
  560. }
  561. return *this;
  562. }
  563. // ----- concatenation -----
  564. path& operator+=(path const& p);
  565. template< typename Source >
  566. typename boost::enable_if_c<
  567. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  568. path&
  569. >::type operator+=(Source const& source)
  570. {
  571. return concat(source);
  572. }
  573. path& operator+=(value_type c)
  574. {
  575. m_pathname.push_back(c);
  576. return *this;
  577. }
  578. template< typename CharT >
  579. typename boost::enable_if_c<
  580. detail::path_traits::is_path_char_type< CharT >::value,
  581. path&
  582. >::type operator+=(CharT c)
  583. {
  584. CharT tmp[2];
  585. tmp[0] = c;
  586. tmp[1] = static_cast< CharT >(0);
  587. concat_op(*this)(tmp, tmp + 1);
  588. return *this;
  589. }
  590. path& concat(path const& p)
  591. {
  592. m_pathname.append(p.m_pathname);
  593. return *this;
  594. }
  595. template< typename Source >
  596. typename boost::enable_if_c<
  597. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >::value,
  598. path&
  599. >::type concat(Source const& source)
  600. {
  601. detail::path_traits::dispatch(source, concat_op(*this));
  602. return *this;
  603. }
  604. template< typename Source >
  605. typename boost::enable_if_c<
  606. boost::conjunction<
  607. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >,
  608. boost::negation< detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type > >
  609. >::value,
  610. path&
  611. >::type concat(Source const& source)
  612. {
  613. detail::path_traits::dispatch_convertible(source, concat_op(*this));
  614. return *this;
  615. }
  616. path& concat(path const& p, codecvt_type const&)
  617. {
  618. m_pathname.append(p.m_pathname);
  619. return *this;
  620. }
  621. template< typename Source >
  622. typename boost::enable_if_c<
  623. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >::value,
  624. path&
  625. >::type concat(Source const& source, codecvt_type const& cvt)
  626. {
  627. detail::path_traits::dispatch(source, concat_op(*this), &cvt);
  628. return *this;
  629. }
  630. template< typename Source >
  631. typename boost::enable_if_c<
  632. boost::conjunction<
  633. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >,
  634. boost::negation< detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type > >
  635. >::value,
  636. path&
  637. >::type concat(Source const& source, codecvt_type const& cvt)
  638. {
  639. detail::path_traits::dispatch_convertible(source, concat_op(*this), &cvt);
  640. return *this;
  641. }
  642. path& concat(const value_type* begin, const value_type* end)
  643. {
  644. m_pathname.append(begin, end);
  645. return *this;
  646. }
  647. template< typename InputIterator >
  648. typename boost::enable_if_c<
  649. boost::conjunction<
  650. detail::path_traits::is_path_source_iterator< InputIterator >,
  651. boost::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
  652. >::value,
  653. path&
  654. >::type concat(InputIterator begin, InputIterator end)
  655. {
  656. if (begin != end)
  657. {
  658. std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source(begin, end);
  659. detail::path_traits::dispatch(source, concat_op(*this));
  660. }
  661. return *this;
  662. }
  663. path& concat(const value_type* begin, const value_type* end, codecvt_type const&)
  664. {
  665. m_pathname.append(begin, end);
  666. return *this;
  667. }
  668. template< typename InputIterator >
  669. typename boost::enable_if_c<
  670. boost::conjunction<
  671. detail::path_traits::is_path_source_iterator< InputIterator >,
  672. boost::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
  673. >::value,
  674. path&
  675. >::type concat(InputIterator begin, InputIterator end, codecvt_type const& cvt)
  676. {
  677. if (begin != end)
  678. {
  679. std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source(begin, end);
  680. detail::path_traits::dispatch(source, concat_op(*this), &cvt);
  681. }
  682. return *this;
  683. }
  684. // ----- appends -----
  685. // if a separator is added, it is the preferred separator for the platform;
  686. // slash for POSIX, backslash for Windows
  687. path& operator/=(path const& p);
  688. template< typename Source >
  689. BOOST_FORCEINLINE typename boost::enable_if_c<
  690. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  691. path&
  692. >::type operator/=(Source const& source)
  693. {
  694. return append(source);
  695. }
  696. path& append(path const& p);
  697. template< typename Source >
  698. BOOST_FORCEINLINE typename boost::enable_if_c<
  699. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >::value,
  700. path&
  701. >::type append(Source const& source)
  702. {
  703. detail::path_traits::dispatch(source, append_op(*this));
  704. return *this;
  705. }
  706. template< typename Source >
  707. BOOST_FORCEINLINE typename boost::enable_if_c<
  708. boost::conjunction<
  709. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >,
  710. boost::negation< detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type > >
  711. >::value,
  712. path&
  713. >::type append(Source const& source)
  714. {
  715. detail::path_traits::dispatch_convertible(source, append_op(*this));
  716. return *this;
  717. }
  718. path& append(path const& p, codecvt_type const&);
  719. template< typename Source >
  720. BOOST_FORCEINLINE typename boost::enable_if_c<
  721. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >::value,
  722. path&
  723. >::type append(Source const& source, codecvt_type const& cvt)
  724. {
  725. detail::path_traits::dispatch(source, append_op(*this), &cvt);
  726. return *this;
  727. }
  728. template< typename Source >
  729. BOOST_FORCEINLINE typename boost::enable_if_c<
  730. boost::conjunction<
  731. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >,
  732. boost::negation< detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type > >
  733. >::value,
  734. path&
  735. >::type append(Source const& source, codecvt_type const& cvt)
  736. {
  737. detail::path_traits::dispatch_convertible(source, append_op(*this), &cvt);
  738. return *this;
  739. }
  740. path& append(const value_type* begin, const value_type* end);
  741. template< typename InputIterator >
  742. BOOST_FORCEINLINE typename boost::enable_if_c<
  743. boost::conjunction<
  744. detail::path_traits::is_path_source_iterator< InputIterator >,
  745. boost::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
  746. >::value,
  747. path&
  748. >::type append(InputIterator begin, InputIterator end)
  749. {
  750. std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source(begin, end);
  751. detail::path_traits::dispatch(source, append_op(*this));
  752. return *this;
  753. }
  754. path& append(const value_type* begin, const value_type* end, codecvt_type const&);
  755. template< typename InputIterator >
  756. BOOST_FORCEINLINE typename boost::enable_if_c<
  757. boost::conjunction<
  758. detail::path_traits::is_path_source_iterator< InputIterator >,
  759. boost::negation< detail::path_traits::is_native_char_ptr< InputIterator > >
  760. >::value,
  761. path&
  762. >::type append(InputIterator begin, InputIterator end, const codecvt_type& cvt)
  763. {
  764. std::basic_string< typename std::iterator_traits< InputIterator >::value_type > source(begin, end);
  765. detail::path_traits::dispatch(source, append_op(*this), &cvt);
  766. return *this;
  767. }
  768. // ----- modifiers -----
  769. void clear() BOOST_NOEXCEPT { m_pathname.clear(); }
  770. #ifdef BOOST_POSIX_API
  771. path& make_preferred()
  772. {
  773. // No effect on POSIX
  774. return *this;
  775. }
  776. #else // BOOST_WINDOWS_API
  777. BOOST_FILESYSTEM_DECL path& make_preferred(); // change slashes to backslashes
  778. #endif
  779. path& remove_filename();
  780. BOOST_FILESYSTEM_DECL path& remove_filename_and_trailing_separators();
  781. BOOST_FILESYSTEM_DECL path& remove_trailing_separator();
  782. BOOST_FILESYSTEM_DECL path& replace_filename(path const& replacement);
  783. path& replace_extension(path const& new_extension = path());
  784. void swap(path& rhs) BOOST_NOEXCEPT { m_pathname.swap(rhs.m_pathname); }
  785. // ----- observers -----
  786. // For operating systems that format file paths differently than directory
  787. // paths, return values from observers are formatted as file names unless there
  788. // is a trailing separator, in which case returns are formatted as directory
  789. // paths. POSIX and Windows make no such distinction.
  790. // Implementations are permitted to return const values or const references.
  791. // The string or path returned by an observer are specified as being formatted
  792. // as "native" or "generic".
  793. //
  794. // For POSIX, these are all the same format; slashes and backslashes are as input and
  795. // are not modified.
  796. //
  797. // For Windows, native: as input; slashes and backslashes are not modified;
  798. // this is the format of the internally stored string.
  799. // generic: backslashes are converted to slashes
  800. // ----- native format observers -----
  801. string_type const& native() const BOOST_NOEXCEPT { return m_pathname; }
  802. const value_type* c_str() const BOOST_NOEXCEPT { return m_pathname.c_str(); }
  803. string_type::size_type size() const BOOST_NOEXCEPT { return m_pathname.size(); }
  804. template< typename String >
  805. String string() const;
  806. template< typename String >
  807. String string(codecvt_type const& cvt) const;
  808. #ifdef BOOST_WINDOWS_API
  809. std::string string() const
  810. {
  811. std::string tmp;
  812. if (!m_pathname.empty())
  813. detail::path_traits::convert(m_pathname.data(), m_pathname.data() + m_pathname.size(), tmp);
  814. return tmp;
  815. }
  816. std::string string(codecvt_type const& cvt) const
  817. {
  818. std::string tmp;
  819. if (!m_pathname.empty())
  820. detail::path_traits::convert(m_pathname.data(), m_pathname.data() + m_pathname.size(), tmp, &cvt);
  821. return tmp;
  822. }
  823. // string_type is std::wstring, so there is no conversion
  824. std::wstring const& wstring() const { return m_pathname; }
  825. std::wstring const& wstring(codecvt_type const&) const { return m_pathname; }
  826. #else // BOOST_POSIX_API
  827. // string_type is std::string, so there is no conversion
  828. std::string const& string() const { return m_pathname; }
  829. std::string const& string(codecvt_type const&) const { return m_pathname; }
  830. std::wstring wstring() const
  831. {
  832. std::wstring tmp;
  833. if (!m_pathname.empty())
  834. detail::path_traits::convert(m_pathname.data(), m_pathname.data() + m_pathname.size(), tmp);
  835. return tmp;
  836. }
  837. std::wstring wstring(codecvt_type const& cvt) const
  838. {
  839. std::wstring tmp;
  840. if (!m_pathname.empty())
  841. detail::path_traits::convert(m_pathname.data(), m_pathname.data() + m_pathname.size(), tmp, &cvt);
  842. return tmp;
  843. }
  844. #endif
  845. // ----- generic format observers -----
  846. // Experimental generic function returning generic formatted path (i.e. separators
  847. // are forward slashes). Motivation: simpler than a family of generic_*string
  848. // functions.
  849. #ifdef BOOST_WINDOWS_API
  850. BOOST_FILESYSTEM_DECL path generic_path() const;
  851. #else
  852. path generic_path() const;
  853. #endif
  854. template< typename String >
  855. String generic_string() const;
  856. template< typename String >
  857. String generic_string(codecvt_type const& cvt) const;
  858. #ifdef BOOST_WINDOWS_API
  859. std::string generic_string() const { return generic_path().string(); }
  860. std::string generic_string(codecvt_type const& cvt) const { return generic_path().string(cvt); }
  861. std::wstring generic_wstring() const { return generic_path().wstring(); }
  862. std::wstring generic_wstring(codecvt_type const&) const { return generic_wstring(); }
  863. #else // BOOST_POSIX_API
  864. // On POSIX-like systems, the generic format is the same as the native format
  865. std::string const& generic_string() const { return m_pathname; }
  866. std::string const& generic_string(codecvt_type const&) const { return m_pathname; }
  867. std::wstring generic_wstring() const { return this->wstring(); }
  868. std::wstring generic_wstring(codecvt_type const& cvt) const { return this->wstring(cvt); }
  869. #endif
  870. // ----- compare -----
  871. int compare(path const& p) const; // generic, lexicographical
  872. template< typename Source >
  873. BOOST_FORCEINLINE typename boost::enable_if_c<
  874. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >::value,
  875. int
  876. >::type compare(Source const& source) const
  877. {
  878. return detail::path_traits::dispatch(source, compare_op(*this));
  879. }
  880. template< typename Source >
  881. BOOST_FORCEINLINE typename boost::enable_if_c<
  882. boost::conjunction<
  883. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >,
  884. boost::negation< detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type > >
  885. >::value,
  886. int
  887. >::type compare(Source const& source) const
  888. {
  889. return detail::path_traits::dispatch_convertible(source, compare_op(*this));
  890. }
  891. template< typename Source >
  892. BOOST_FORCEINLINE typename boost::enable_if_c<
  893. detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type >::value,
  894. int
  895. >::type compare(Source const& source, codecvt_type const& cvt) const
  896. {
  897. return detail::path_traits::dispatch(source, compare_op(*this), &cvt);
  898. }
  899. template< typename Source >
  900. BOOST_FORCEINLINE typename boost::enable_if_c<
  901. boost::conjunction<
  902. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >,
  903. boost::negation< detail::path_traits::is_path_source< typename boost::remove_cv< Source >::type > >
  904. >::value,
  905. int
  906. >::type compare(Source const& source, codecvt_type const& cvt) const
  907. {
  908. return detail::path_traits::dispatch_convertible(source, compare_op(*this), &cvt);
  909. }
  910. // ----- decomposition -----
  911. path root_path() const { return path(m_pathname.c_str(), m_pathname.c_str() + detail::path_algorithms::find_root_path_size(*this)); }
  912. // returns 0 or 1 element path even on POSIX, root_name() is non-empty() for network paths
  913. path root_name() const { return path(m_pathname.c_str(), m_pathname.c_str() + detail::path_algorithms::find_root_name_size(*this)); }
  914. // returns 0 or 1 element path
  915. path root_directory() const
  916. {
  917. detail::path_algorithms::substring root_dir = detail::path_algorithms::find_root_directory(*this);
  918. const value_type* p = m_pathname.c_str() + root_dir.pos;
  919. return path(p, p + root_dir.size);
  920. }
  921. path relative_path() const
  922. {
  923. detail::path_algorithms::substring rel_path = detail::path_algorithms::find_relative_path(*this);
  924. const value_type* p = m_pathname.c_str() + rel_path.pos;
  925. return path(p, p + rel_path.size);
  926. }
  927. path parent_path() const { return path(m_pathname.c_str(), m_pathname.c_str() + detail::path_algorithms::find_parent_path_size(*this)); }
  928. path filename() const; // returns 0 or 1 element path
  929. path stem() const; // returns 0 or 1 element path
  930. path extension() const; // returns 0 or 1 element path
  931. // ----- query -----
  932. bool empty() const BOOST_NOEXCEPT { return m_pathname.empty(); }
  933. bool filename_is_dot() const;
  934. bool filename_is_dot_dot() const;
  935. bool has_root_path() const { return detail::path_algorithms::find_root_path_size(*this) > 0; }
  936. bool has_root_name() const { return detail::path_algorithms::find_root_name_size(*this) > 0; }
  937. bool has_root_directory() const { return detail::path_algorithms::find_root_directory(*this).size > 0; }
  938. bool has_relative_path() const { return detail::path_algorithms::find_relative_path(*this).size > 0; }
  939. bool has_parent_path() const { return detail::path_algorithms::find_parent_path_size(*this) > 0; }
  940. bool has_filename() const;
  941. bool has_stem() const { return !stem().empty(); }
  942. bool has_extension() const { return !extension().empty(); }
  943. bool is_relative() const { return !is_absolute(); }
  944. bool is_absolute() const
  945. {
  946. // Windows CE has no root name (aka drive letters)
  947. #if defined(BOOST_WINDOWS_API) && !defined(UNDER_CE)
  948. return has_root_name() && has_root_directory();
  949. #else
  950. return has_root_directory();
  951. #endif
  952. }
  953. // ----- lexical operations -----
  954. path lexically_normal() const;
  955. BOOST_FILESYSTEM_DECL path lexically_relative(path const& base) const;
  956. path lexically_proximate(path const& base) const;
  957. // ----- iterators -----
  958. BOOST_FILESYSTEM_DECL iterator begin() const;
  959. BOOST_FILESYSTEM_DECL iterator end() const;
  960. reverse_iterator rbegin() const;
  961. reverse_iterator rend() const;
  962. // ----- static member functions -----
  963. static BOOST_FILESYSTEM_DECL std::locale imbue(std::locale const& loc);
  964. static BOOST_FILESYSTEM_DECL codecvt_type const& codecvt();
  965. // ----- deprecated functions -----
  966. #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
  967. // recently deprecated functions supplied by default
  968. path& normalize();
  969. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::remove_filename() instead")
  970. path& remove_leaf() { return remove_filename(); }
  971. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::filename() instead")
  972. path leaf() const { return filename(); }
  973. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::parent_path() instead")
  974. path branch_path() const { return parent_path(); }
  975. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::generic_path() instead")
  976. path generic() const { return generic_path(); }
  977. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use !path::empty() instead")
  978. bool has_leaf() const { return !m_pathname.empty(); }
  979. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::has_parent_path() instead")
  980. bool has_branch_path() const { return has_parent_path(); }
  981. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::is_absolute() instead")
  982. bool is_complete() const { return is_absolute(); }
  983. #endif
  984. #if defined(BOOST_FILESYSTEM_DEPRECATED)
  985. // deprecated functions with enough signature or semantic changes that they are
  986. // not supplied by default
  987. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::string() instead")
  988. std::string file_string() const { return string(); }
  989. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::string() instead")
  990. std::string directory_string() const { return string(); }
  991. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::string() instead")
  992. std::string native_file_string() const { return string(); }
  993. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::string() instead")
  994. std::string native_directory_string() const { return string(); }
  995. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::native() instead")
  996. string_type external_file_string() const { return native(); }
  997. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::native() instead")
  998. string_type external_directory_string() const { return native(); }
  999. #endif
  1000. //--------------------------------------------------------------------------------------//
  1001. // class path private members //
  1002. //--------------------------------------------------------------------------------------//
  1003. private:
  1004. /*
  1005. * m_pathname has the type, encoding, and format required by the native
  1006. * operating system. Thus for POSIX and Windows there is no conversion for
  1007. * passing m_pathname.c_str() to the O/S API or when obtaining a path from the
  1008. * O/S API. POSIX encoding is unspecified other than for dot and slash
  1009. * characters; POSIX just treats paths as a sequence of bytes. Windows
  1010. * encoding is UCS-2 or UTF-16 depending on the version.
  1011. */
  1012. string_type m_pathname; // Windows: as input; backslashes NOT converted to slashes,
  1013. // slashes NOT converted to backslashes
  1014. };
  1015. namespace detail {
  1016. BOOST_FILESYSTEM_DECL path const& dot_path();
  1017. BOOST_FILESYSTEM_DECL path const& dot_dot_path();
  1018. } // namespace detail
  1019. #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
  1020. typedef path wpath;
  1021. #endif
  1022. namespace path_detail {
  1023. //------------------------------------------------------------------------------------//
  1024. // class path::iterator //
  1025. //------------------------------------------------------------------------------------//
  1026. class path_iterator :
  1027. public boost::iterator_facade<
  1028. path_iterator,
  1029. const path,
  1030. boost::bidirectional_traversal_tag
  1031. >
  1032. {
  1033. private:
  1034. friend class boost::iterator_core_access;
  1035. friend class boost::filesystem::path;
  1036. friend class path_reverse_iterator;
  1037. friend struct boost::filesystem::detail::path_algorithms;
  1038. path const& dereference() const { return m_element; }
  1039. bool equal(path_iterator const& rhs) const BOOST_NOEXCEPT
  1040. {
  1041. return m_path_ptr == rhs.m_path_ptr && m_pos == rhs.m_pos;
  1042. }
  1043. void increment();
  1044. void decrement();
  1045. private:
  1046. // current element
  1047. path m_element;
  1048. // path being iterated over
  1049. const path* m_path_ptr;
  1050. // position of m_element in m_path_ptr->m_pathname.
  1051. // if m_element is implicit dot, m_pos is the
  1052. // position of the last separator in the path.
  1053. // end() iterator is indicated by
  1054. // m_pos == m_path_ptr->m_pathname.size()
  1055. path::string_type::size_type m_pos;
  1056. };
  1057. //------------------------------------------------------------------------------------//
  1058. // class path::reverse_iterator //
  1059. //------------------------------------------------------------------------------------//
  1060. class path_reverse_iterator :
  1061. public boost::iterator_facade<
  1062. path_reverse_iterator,
  1063. const path,
  1064. boost::bidirectional_traversal_tag
  1065. >
  1066. {
  1067. public:
  1068. explicit path_reverse_iterator(path_iterator itr) :
  1069. m_itr(itr)
  1070. {
  1071. if (itr != itr.m_path_ptr->begin())
  1072. m_element = *--itr;
  1073. }
  1074. private:
  1075. friend class boost::iterator_core_access;
  1076. friend class boost::filesystem::path;
  1077. path const& dereference() const { return m_element; }
  1078. bool equal(path_reverse_iterator const& rhs) const BOOST_NOEXCEPT { return m_itr == rhs.m_itr; }
  1079. void increment()
  1080. {
  1081. --m_itr;
  1082. if (m_itr != m_itr.m_path_ptr->begin())
  1083. {
  1084. path_iterator tmp = m_itr;
  1085. m_element = *--tmp;
  1086. }
  1087. }
  1088. void decrement()
  1089. {
  1090. m_element = *m_itr;
  1091. ++m_itr;
  1092. }
  1093. private:
  1094. path_iterator m_itr;
  1095. path m_element;
  1096. };
  1097. // std::lexicographical_compare would infinitely recurse because path iterators
  1098. // yield paths, so provide a path aware version
  1099. bool lexicographical_compare(path_iterator first1, path_iterator const& last1, path_iterator first2, path_iterator const& last2);
  1100. } // namespace path_detail
  1101. using path_detail::lexicographical_compare;
  1102. //------------------------------------------------------------------------------------//
  1103. // //
  1104. // non-member functions //
  1105. // //
  1106. //------------------------------------------------------------------------------------//
  1107. BOOST_FORCEINLINE bool operator==(path const& lhs, path const& rhs)
  1108. {
  1109. return lhs.compare(rhs) == 0;
  1110. }
  1111. template< typename Source >
  1112. BOOST_FORCEINLINE typename boost::enable_if_c<
  1113. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1114. bool
  1115. >::type operator==(path const& lhs, Source const& rhs)
  1116. {
  1117. return lhs.compare(rhs) == 0;
  1118. }
  1119. template< typename Source >
  1120. BOOST_FORCEINLINE typename boost::enable_if_c<
  1121. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1122. bool
  1123. >::type operator==(Source const& lhs, path const& rhs)
  1124. {
  1125. return rhs.compare(lhs) == 0;
  1126. }
  1127. BOOST_FORCEINLINE bool operator!=(path const& lhs, path const& rhs)
  1128. {
  1129. return lhs.compare(rhs) != 0;
  1130. }
  1131. template< typename Source >
  1132. BOOST_FORCEINLINE typename boost::enable_if_c<
  1133. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1134. bool
  1135. >::type operator!=(path const& lhs, Source const& rhs)
  1136. {
  1137. return lhs.compare(rhs) != 0;
  1138. }
  1139. template< typename Source >
  1140. BOOST_FORCEINLINE typename boost::enable_if_c<
  1141. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1142. bool
  1143. >::type operator!=(Source const& lhs, path const& rhs)
  1144. {
  1145. return rhs.compare(lhs) != 0;
  1146. }
  1147. BOOST_FORCEINLINE bool operator<(path const& lhs, path const& rhs)
  1148. {
  1149. return lhs.compare(rhs) < 0;
  1150. }
  1151. template< typename Source >
  1152. BOOST_FORCEINLINE typename boost::enable_if_c<
  1153. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1154. bool
  1155. >::type operator<(path const& lhs, Source const& rhs)
  1156. {
  1157. return lhs.compare(rhs) < 0;
  1158. }
  1159. template< typename Source >
  1160. BOOST_FORCEINLINE typename boost::enable_if_c<
  1161. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1162. bool
  1163. >::type operator<(Source const& lhs, path const& rhs)
  1164. {
  1165. return rhs.compare(lhs) > 0;
  1166. }
  1167. BOOST_FORCEINLINE bool operator<=(path const& lhs, path const& rhs)
  1168. {
  1169. return lhs.compare(rhs) <= 0;
  1170. }
  1171. template< typename Source >
  1172. BOOST_FORCEINLINE typename boost::enable_if_c<
  1173. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1174. bool
  1175. >::type operator<=(path const& lhs, Source const& rhs)
  1176. {
  1177. return lhs.compare(rhs) <= 0;
  1178. }
  1179. template< typename Source >
  1180. BOOST_FORCEINLINE typename boost::enable_if_c<
  1181. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1182. bool
  1183. >::type operator<=(Source const& lhs, path const& rhs)
  1184. {
  1185. return rhs.compare(lhs) >= 0;
  1186. }
  1187. BOOST_FORCEINLINE bool operator>(path const& lhs, path const& rhs)
  1188. {
  1189. return lhs.compare(rhs) > 0;
  1190. }
  1191. template< typename Source >
  1192. BOOST_FORCEINLINE typename boost::enable_if_c<
  1193. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1194. bool
  1195. >::type operator>(path const& lhs, Source const& rhs)
  1196. {
  1197. return lhs.compare(rhs) > 0;
  1198. }
  1199. template< typename Source >
  1200. BOOST_FORCEINLINE typename boost::enable_if_c<
  1201. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1202. bool
  1203. >::type operator>(Source const& lhs, path const& rhs)
  1204. {
  1205. return rhs.compare(lhs) < 0;
  1206. }
  1207. BOOST_FORCEINLINE bool operator>=(path const& lhs, path const& rhs)
  1208. {
  1209. return lhs.compare(rhs) >= 0;
  1210. }
  1211. template< typename Source >
  1212. BOOST_FORCEINLINE typename boost::enable_if_c<
  1213. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1214. bool
  1215. >::type operator>=(path const& lhs, Source const& rhs)
  1216. {
  1217. return lhs.compare(rhs) >= 0;
  1218. }
  1219. template< typename Source >
  1220. BOOST_FORCEINLINE typename boost::enable_if_c<
  1221. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1222. bool
  1223. >::type operator>=(Source const& lhs, path const& rhs)
  1224. {
  1225. return rhs.compare(lhs) <= 0;
  1226. }
  1227. // Note: Declared as a template to delay binding to Boost.ContainerHash functions and make the dependency optional
  1228. template< typename T >
  1229. inline typename boost::enable_if_c<
  1230. boost::is_same< T, path >::value,
  1231. std::size_t
  1232. >::type hash_value(T const& p) BOOST_NOEXCEPT
  1233. {
  1234. #ifdef BOOST_WINDOWS_API
  1235. std::size_t seed = 0u;
  1236. for (typename T::value_type const* it = p.c_str(); *it; ++it)
  1237. hash_combine(seed, *it == L'/' ? L'\\' : *it);
  1238. return seed;
  1239. #else // BOOST_POSIX_API
  1240. return hash_range(p.native().begin(), p.native().end());
  1241. #endif
  1242. }
  1243. inline void swap(path& lhs, path& rhs) BOOST_NOEXCEPT
  1244. {
  1245. lhs.swap(rhs);
  1246. }
  1247. BOOST_FORCEINLINE path operator/(path lhs, path const& rhs)
  1248. {
  1249. lhs.append(rhs);
  1250. return lhs;
  1251. }
  1252. template< typename Source >
  1253. BOOST_FORCEINLINE typename boost::enable_if_c<
  1254. detail::path_traits::is_convertible_to_path_source< typename boost::remove_cv< Source >::type >::value,
  1255. path
  1256. >::type operator/(path lhs, Source const& rhs)
  1257. {
  1258. lhs.append(rhs);
  1259. return lhs;
  1260. }
  1261. // inserters and extractors
  1262. // use boost::io::quoted() to handle spaces in paths
  1263. // use '&' as escape character to ease use for Windows paths
  1264. template< typename Char, typename Traits >
  1265. inline std::basic_ostream< Char, Traits >&
  1266. operator<<(std::basic_ostream< Char, Traits >& os, path const& p)
  1267. {
  1268. return os << boost::io::quoted(p.template string< std::basic_string< Char > >(), static_cast< Char >('&'));
  1269. }
  1270. template< typename Char, typename Traits >
  1271. inline std::basic_istream< Char, Traits >&
  1272. operator>>(std::basic_istream< Char, Traits >& is, path& p)
  1273. {
  1274. std::basic_string< Char > str;
  1275. is >> boost::io::quoted(str, static_cast< Char >('&'));
  1276. p = str;
  1277. return is;
  1278. }
  1279. // name_checks
  1280. // These functions are holdovers from version 1. It isn't clear they have much
  1281. // usefulness, or how to generalize them for later versions.
  1282. BOOST_FILESYSTEM_DECL bool portable_posix_name(std::string const& name);
  1283. BOOST_FILESYSTEM_DECL bool windows_name(std::string const& name);
  1284. BOOST_FILESYSTEM_DECL bool portable_name(std::string const& name);
  1285. BOOST_FILESYSTEM_DECL bool portable_directory_name(std::string const& name);
  1286. BOOST_FILESYSTEM_DECL bool portable_file_name(std::string const& name);
  1287. BOOST_FILESYSTEM_DECL bool native(std::string const& name);
  1288. namespace detail {
  1289. // For POSIX, is_directory_separator() and is_element_separator() are identical since
  1290. // a forward slash is the only valid directory separator and also the only valid
  1291. // element separator. For Windows, forward slash and back slash are the possible
  1292. // directory separators, but colon (example: "c:foo") is also an element separator.
  1293. inline bool is_directory_separator(path::value_type c) BOOST_NOEXCEPT
  1294. {
  1295. return c == path::separator
  1296. #ifdef BOOST_WINDOWS_API
  1297. || c == path::preferred_separator
  1298. #endif
  1299. ;
  1300. }
  1301. inline bool is_element_separator(path::value_type c) BOOST_NOEXCEPT
  1302. {
  1303. return c == path::separator
  1304. #ifdef BOOST_WINDOWS_API
  1305. || c == path::preferred_separator || c == L':'
  1306. #endif
  1307. ;
  1308. }
  1309. } // namespace detail
  1310. //------------------------------------------------------------------------------------//
  1311. // class path miscellaneous function implementations //
  1312. //------------------------------------------------------------------------------------//
  1313. namespace detail {
  1314. inline bool path_algorithms::has_filename_v3(path const& p)
  1315. {
  1316. return !p.m_pathname.empty();
  1317. }
  1318. inline bool path_algorithms::has_filename_v4(path const& p)
  1319. {
  1320. return path_algorithms::find_filename_v4_size(p) > 0;
  1321. }
  1322. inline path path_algorithms::filename_v4(path const& p)
  1323. {
  1324. string_type::size_type filename_size = path_algorithms::find_filename_v4_size(p);
  1325. string_type::size_type pos = p.m_pathname.size() - filename_size;
  1326. const value_type* ptr = p.m_pathname.c_str() + pos;
  1327. return path(ptr, ptr + filename_size);
  1328. }
  1329. inline path path_algorithms::extension_v4(path const& p)
  1330. {
  1331. string_type::size_type extension_size = path_algorithms::find_extension_v4_size(p);
  1332. string_type::size_type pos = p.m_pathname.size() - extension_size;
  1333. const value_type* ptr = p.m_pathname.c_str() + pos;
  1334. return path(ptr, ptr + extension_size);
  1335. }
  1336. inline void path_algorithms::append_v4(path& left, path const& right)
  1337. {
  1338. path_algorithms::append_v4(left, right.m_pathname.c_str(), right.m_pathname.c_str() + right.m_pathname.size());
  1339. }
  1340. } // namespace detail
  1341. // Note: Because of the range constructor in C++23 std::string_view that involves a check for contiguous_range concept,
  1342. // any non-template function call that requires a check whether the source argument (which may be fs::path)
  1343. // is convertible to std::string_view must be made after fs::path::iterator is defined. This includes overload
  1344. // resolution and SFINAE checks. Otherwise, the concept check result formally changes between fs::path::iterator
  1345. // is not defined and defined, which causes compilation errors with gcc 11 and later.
  1346. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106808
  1347. BOOST_FORCEINLINE path::compare_op::result_type path::compare_op::operator() (const value_type* source, const value_type* source_end, const codecvt_type*) const
  1348. {
  1349. path src;
  1350. src.m_pathname.assign(source, source_end);
  1351. return m_self.compare(src);
  1352. }
  1353. template< typename OtherChar >
  1354. BOOST_FORCEINLINE path::compare_op::result_type path::compare_op::operator() (const OtherChar* source, const OtherChar* source_end, const codecvt_type* cvt) const
  1355. {
  1356. path src;
  1357. detail::path_traits::convert(source, source_end, src.m_pathname, cvt);
  1358. return m_self.compare(src);
  1359. }
  1360. inline path& path::operator=(path const& p)
  1361. {
  1362. return assign(p);
  1363. }
  1364. inline path& path::operator+=(path const& p)
  1365. {
  1366. return concat(p);
  1367. }
  1368. BOOST_FORCEINLINE path& path::operator/=(path const& p)
  1369. {
  1370. return append(p);
  1371. }
  1372. #if !defined(BOOST_WINDOWS_API)
  1373. inline path path::generic_path() const
  1374. {
  1375. return path(*this);
  1376. }
  1377. #endif
  1378. inline path path::lexically_proximate(path const& base) const
  1379. {
  1380. path tmp(lexically_relative(base));
  1381. return tmp.empty() ? *this : tmp;
  1382. }
  1383. inline path::reverse_iterator path::rbegin() const
  1384. {
  1385. return reverse_iterator(end());
  1386. }
  1387. inline path::reverse_iterator path::rend() const
  1388. {
  1389. return reverse_iterator(begin());
  1390. }
  1391. inline bool path::filename_is_dot() const
  1392. {
  1393. // implicit dot is tricky, so actually call filename(); see path::filename() example
  1394. // in reference.html
  1395. path p(filename());
  1396. return p.size() == 1 && *p.c_str() == dot;
  1397. }
  1398. inline bool path::filename_is_dot_dot() const
  1399. {
  1400. 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]));
  1401. // use detail::is_element_separator() rather than detail::is_directory_separator
  1402. // to deal with "c:.." edge case on Windows when ':' acts as a separator
  1403. }
  1404. #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
  1405. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use path::lexically_normal() instead")
  1406. BOOST_FORCEINLINE path& path::normalize()
  1407. {
  1408. path tmp(lexically_normal());
  1409. m_pathname.swap(tmp.m_pathname);
  1410. return *this;
  1411. }
  1412. #endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
  1413. // The following functions are defined differently, depending on Boost.Filesystem version in use.
  1414. // To avoid ODR violation, these functions are not defined when the library itself is built.
  1415. // This makes sure they are not compiled when the library is built, and the only version there is
  1416. // is the one in user's code. Users are supposed to consistently use the same Boost.Filesystem version
  1417. // in all their translation units.
  1418. #if !defined(BOOST_FILESYSTEM_SOURCE)
  1419. BOOST_FORCEINLINE path& path::append(path const& p)
  1420. {
  1421. BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::append)(*this, p.m_pathname.data(), p.m_pathname.data() + p.m_pathname.size());
  1422. return *this;
  1423. }
  1424. BOOST_FORCEINLINE path& path::append(path const& p, codecvt_type const&)
  1425. {
  1426. BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::append)(*this, p.m_pathname.data(), p.m_pathname.data() + p.m_pathname.size());
  1427. return *this;
  1428. }
  1429. BOOST_FORCEINLINE path& path::append(const value_type* begin, const value_type* end)
  1430. {
  1431. BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::append)(*this, begin, end);
  1432. return *this;
  1433. }
  1434. BOOST_FORCEINLINE path& path::append(const value_type* begin, const value_type* end, codecvt_type const&)
  1435. {
  1436. BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::append)(*this, begin, end);
  1437. return *this;
  1438. }
  1439. BOOST_FORCEINLINE path& path::remove_filename()
  1440. {
  1441. BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::remove_filename)(*this);
  1442. return *this;
  1443. }
  1444. BOOST_FORCEINLINE path& path::replace_extension(path const& new_extension)
  1445. {
  1446. BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::replace_extension)(*this, new_extension);
  1447. return *this;
  1448. }
  1449. BOOST_FORCEINLINE int path::compare(path const& p) const
  1450. {
  1451. return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::compare)(*this, p);
  1452. }
  1453. BOOST_FORCEINLINE path path::filename() const
  1454. {
  1455. return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::filename)(*this);
  1456. }
  1457. BOOST_FORCEINLINE path path::stem() const
  1458. {
  1459. return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::stem)(*this);
  1460. }
  1461. BOOST_FORCEINLINE path path::extension() const
  1462. {
  1463. return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::extension)(*this);
  1464. }
  1465. BOOST_FORCEINLINE bool path::has_filename() const
  1466. {
  1467. return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::has_filename)(*this);
  1468. }
  1469. BOOST_FORCEINLINE path path::lexically_normal() const
  1470. {
  1471. return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::lexically_normal)(*this);
  1472. }
  1473. namespace path_detail {
  1474. BOOST_FORCEINLINE void path_iterator::increment()
  1475. {
  1476. BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::increment)(*this);
  1477. }
  1478. BOOST_FORCEINLINE void path_iterator::decrement()
  1479. {
  1480. BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::decrement)(*this);
  1481. }
  1482. BOOST_FORCEINLINE bool lexicographical_compare(path_iterator first1, path_iterator const& last1, path_iterator first2, path_iterator const& last2)
  1483. {
  1484. return BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::lex_compare)(first1, last1, first2, last2) < 0;
  1485. }
  1486. } // namespace path_detail
  1487. #endif // !defined(BOOST_FILESYSTEM_SOURCE)
  1488. //--------------------------------------------------------------------------------------//
  1489. // class path member template specializations //
  1490. //--------------------------------------------------------------------------------------//
  1491. template< >
  1492. inline std::string path::string< std::string >() const
  1493. {
  1494. return string();
  1495. }
  1496. template< >
  1497. inline std::wstring path::string< std::wstring >() const
  1498. {
  1499. return wstring();
  1500. }
  1501. template< >
  1502. inline std::string path::string< std::string >(codecvt_type const& cvt) const
  1503. {
  1504. return string(cvt);
  1505. }
  1506. template< >
  1507. inline std::wstring path::string< std::wstring >(codecvt_type const& cvt) const
  1508. {
  1509. return wstring(cvt);
  1510. }
  1511. template< >
  1512. inline std::string path::generic_string< std::string >() const
  1513. {
  1514. return generic_string();
  1515. }
  1516. template< >
  1517. inline std::wstring path::generic_string< std::wstring >() const
  1518. {
  1519. return generic_wstring();
  1520. }
  1521. template< >
  1522. inline std::string path::generic_string< std::string >(codecvt_type const& cvt) const
  1523. {
  1524. return generic_string(cvt);
  1525. }
  1526. template< >
  1527. inline std::wstring path::generic_string< std::wstring >(codecvt_type const& cvt) const
  1528. {
  1529. return generic_wstring(cvt);
  1530. }
  1531. } // namespace filesystem
  1532. } // namespace boost
  1533. //----------------------------------------------------------------------------//
  1534. #include <boost/filesystem/detail/footer.hpp>
  1535. #endif // BOOST_FILESYSTEM_PATH_HPP