blob: f29e23e1816635d130822ac0ec0538ca5a383c92 [file] [log] [blame]
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001// -*- C++ -*-
2//===--------------------------- filesystem -------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10#ifndef _LIBCPP_EXPERIMENTAL_FILESYSTEM
11#define _LIBCPP_EXPERIMENTAL_FILESYSTEM
12/*
13 filesystem synopsis
14
15 namespace std { namespace experimental { namespace filesystem { inline namespace v1 {
16
17 class path;
18
19 void swap(path& lhs, path& rhs) _NOEXCEPT;
20 size_t hash_value(const path& p) _NOEXCEPT;
21
22 bool operator==(const path& lhs, const path& rhs) _NOEXCEPT;
23 bool operator!=(const path& lhs, const path& rhs) _NOEXCEPT;
24 bool operator< (const path& lhs, const path& rhs) _NOEXCEPT;
25 bool operator<=(const path& lhs, const path& rhs) _NOEXCEPT;
26 bool operator> (const path& lhs, const path& rhs) _NOEXCEPT;
27 bool operator>=(const path& lhs, const path& rhs) _NOEXCEPT;
28
29 path operator/ (const path& lhs, const path& rhs);
30
Eric Fiselier0b47a652018-02-04 03:10:53 +000031 // fs.path.io operators are friends of path.
Eric Fiselier6e9a6942016-06-17 19:46:40 +000032 template <class charT, class traits>
Eric Fiselier0b47a652018-02-04 03:10:53 +000033 friend basic_ostream<charT, traits>&
Eric Fiselier6e9a6942016-06-17 19:46:40 +000034 operator<<(basic_ostream<charT, traits>& os, const path& p);
35
36 template <class charT, class traits>
Eric Fiselier0b47a652018-02-04 03:10:53 +000037 friend basic_istream<charT, traits>&
Eric Fiselier6e9a6942016-06-17 19:46:40 +000038 operator>>(basic_istream<charT, traits>& is, path& p);
39
40 template <class Source>
41 path u8path(const Source& source);
42 template <class InputIterator>
43 path u8path(InputIterator first, InputIterator last);
44
45 class filesystem_error;
46 class directory_entry;
47
48 class directory_iterator;
49
50 // enable directory_iterator range-based for statements
51 directory_iterator begin(directory_iterator iter) noexcept;
52 directory_iterator end(const directory_iterator&) noexcept;
53
54 class recursive_directory_iterator;
55
56 // enable recursive_directory_iterator range-based for statements
57 recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
58 recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
59
60 class file_status;
61
62 struct space_info
63 {
64 uintmax_t capacity;
65 uintmax_t free;
66 uintmax_t available;
67 };
68
69 enum class file_type;
70 enum class perms;
Eric Fiselierf2c93732018-03-26 06:23:55 +000071 enum class perm_options;
Eric Fiselier6e9a6942016-06-17 19:46:40 +000072 enum class copy_options;
73 enum class directory_options;
74
75 typedef chrono::time_point<trivial-clock> file_time_type;
76
77 // operational functions
78
Eric Fiselier1e34c762018-04-02 23:03:41 +000079 path absolute(const path& p);
80 path absolute(const path& p, error_code &ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +000081
Eric Fiselier1e34c762018-04-02 23:03:41 +000082 path canonical(const path& p);
Eric Fiselier6e9a6942016-06-17 19:46:40 +000083 path canonical(const path& p, error_code& ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +000084
85 void copy(const path& from, const path& to);
Eric Fiseliera4c272d2017-10-30 18:59:59 +000086 void copy(const path& from, const path& to, error_code& ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +000087 void copy(const path& from, const path& to, copy_options options);
88 void copy(const path& from, const path& to, copy_options options,
Eric Fiseliera4c272d2017-10-30 18:59:59 +000089 error_code& ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +000090
91 bool copy_file(const path& from, const path& to);
Eric Fiselier4d0f4282018-02-04 07:35:36 +000092 bool copy_file(const path& from, const path& to, error_code& ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +000093 bool copy_file(const path& from, const path& to, copy_options option);
94 bool copy_file(const path& from, const path& to, copy_options option,
Eric Fiselier4d0f4282018-02-04 07:35:36 +000095 error_code& ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +000096
97 void copy_symlink(const path& existing_symlink, const path& new_symlink);
98 void copy_symlink(const path& existing_symlink, const path& new_symlink,
99 error_code& ec) _NOEXCEPT;
100
101 bool create_directories(const path& p);
Eric Fiselier4d0f4282018-02-04 07:35:36 +0000102 bool create_directories(const path& p, error_code& ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000103
104 bool create_directory(const path& p);
105 bool create_directory(const path& p, error_code& ec) _NOEXCEPT;
106
107 bool create_directory(const path& p, const path& attributes);
108 bool create_directory(const path& p, const path& attributes,
109 error_code& ec) _NOEXCEPT;
110
111 void create_directory_symlink(const path& to, const path& new_symlink);
112 void create_directory_symlink(const path& to, const path& new_symlink,
113 error_code& ec) _NOEXCEPT;
114
115 void create_hard_link(const path& to, const path& new_hard_link);
116 void create_hard_link(const path& to, const path& new_hard_link,
117 error_code& ec) _NOEXCEPT;
118
119 void create_symlink(const path& to, const path& new_symlink);
120 void create_symlink(const path& to, const path& new_symlink,
121 error_code& ec) _NOEXCEPT;
122
123 path current_path();
124 path current_path(error_code& ec);
125 void current_path(const path& p);
126 void current_path(const path& p, error_code& ec) _NOEXCEPT;
127
128 bool exists(file_status s) _NOEXCEPT;
129 bool exists(const path& p);
130 bool exists(const path& p, error_code& ec) _NOEXCEPT;
131
132 bool equivalent(const path& p1, const path& p2);
133 bool equivalent(const path& p1, const path& p2, error_code& ec) _NOEXCEPT;
134
135 uintmax_t file_size(const path& p);
136 uintmax_t file_size(const path& p, error_code& ec) _NOEXCEPT;
137
138 uintmax_t hard_link_count(const path& p);
139 uintmax_t hard_link_count(const path& p, error_code& ec) _NOEXCEPT;
140
141 bool is_block_file(file_status s) _NOEXCEPT;
142 bool is_block_file(const path& p);
143 bool is_block_file(const path& p, error_code& ec) _NOEXCEPT;
144
145 bool is_character_file(file_status s) _NOEXCEPT;
146 bool is_character_file(const path& p);
147 bool is_character_file(const path& p, error_code& ec) _NOEXCEPT;
148
149 bool is_directory(file_status s) _NOEXCEPT;
150 bool is_directory(const path& p);
151 bool is_directory(const path& p, error_code& ec) _NOEXCEPT;
152
153 bool is_empty(const path& p);
154 bool is_empty(const path& p, error_code& ec) _NOEXCEPT;
155
156 bool is_fifo(file_status s) _NOEXCEPT;
157 bool is_fifo(const path& p);
158 bool is_fifo(const path& p, error_code& ec) _NOEXCEPT;
159
160 bool is_other(file_status s) _NOEXCEPT;
161 bool is_other(const path& p);
162 bool is_other(const path& p, error_code& ec) _NOEXCEPT;
163
164 bool is_regular_file(file_status s) _NOEXCEPT;
165 bool is_regular_file(const path& p);
166 bool is_regular_file(const path& p, error_code& ec) _NOEXCEPT;
167
168 bool is_socket(file_status s) _NOEXCEPT;
169 bool is_socket(const path& p);
170 bool is_socket(const path& p, error_code& ec) _NOEXCEPT;
171
172 bool is_symlink(file_status s) _NOEXCEPT;
173 bool is_symlink(const path& p);
174 bool is_symlink(const path& p, error_code& ec) _NOEXCEPT;
175
176 file_time_type last_write_time(const path& p);
177 file_time_type last_write_time(const path& p, error_code& ec) _NOEXCEPT;
178 void last_write_time(const path& p, file_time_type new_time);
179 void last_write_time(const path& p, file_time_type new_time,
180 error_code& ec) _NOEXCEPT;
181
Eric Fiselierf2c93732018-03-26 06:23:55 +0000182 void permissions(const path& p, perms prms,
183 perm_options opts=perm_options::replace);
184 void permissions(const path& p, perms prms, error_code& ec) noexcept;
185 void permissions(const path& p, perms prms, perm_options opts,
186 error_code& ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000187
Eric Fiselier1e34c762018-04-02 23:03:41 +0000188 path proximate(const path& p, error_code& ec);
189 path proximate(const path& p, const path& base = current_path());
190 path proximate(const path& p, const path& base, error_code &ec);
191
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000192 path read_symlink(const path& p);
193 path read_symlink(const path& p, error_code& ec);
194
Eric Fiselier1e34c762018-04-02 23:03:41 +0000195 path relative(const path& p, error_code& ec);
196 path relative(const path& p, const path& base=current_path());
197 path relative(const path& p, const path& base, error_code& ec);
198
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000199 bool remove(const path& p);
200 bool remove(const path& p, error_code& ec) _NOEXCEPT;
201
202 uintmax_t remove_all(const path& p);
Eric Fiselier4d0f4282018-02-04 07:35:36 +0000203 uintmax_t remove_all(const path& p, error_code& ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000204
205 void rename(const path& from, const path& to);
206 void rename(const path& from, const path& to, error_code& ec) _NOEXCEPT;
207
208 void resize_file(const path& p, uintmax_t size);
209 void resize_file(const path& p, uintmax_t size, error_code& ec) _NOEXCEPT;
210
211 space_info space(const path& p);
212 space_info space(const path& p, error_code& ec) _NOEXCEPT;
213
214 file_status status(const path& p);
215 file_status status(const path& p, error_code& ec) _NOEXCEPT;
216
217 bool status_known(file_status s) _NOEXCEPT;
218
219 file_status symlink_status(const path& p);
220 file_status symlink_status(const path& p, error_code& ec) _NOEXCEPT;
221
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000222 path temp_directory_path();
223 path temp_directory_path(error_code& ec);
224
Eric Fiselier1e34c762018-04-02 23:03:41 +0000225 path weakly_canonical(path const& p);
226 path weakly_canonical(path const& p, error_code& ec);
227
228
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000229} } } } // namespaces std::experimental::filesystem::v1
230
231*/
232
233#include <experimental/__config>
234#include <cstddef>
235#include <chrono>
236#include <iterator>
237#include <iosfwd>
238#include <locale>
239#include <memory>
240#include <stack>
241#include <string>
242#include <system_error>
243#include <utility>
244#include <iomanip> // for quoted
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000245#include <string_view>
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000246
247#include <__debug>
248
249#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
250#pragma GCC system_header
251#endif
252
253#define __cpp_lib_experimental_filesystem 201406
254
255_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM
256
257typedef chrono::time_point<std::chrono::system_clock> file_time_type;
258
259struct _LIBCPP_TYPE_VIS space_info
260{
261 uintmax_t capacity;
262 uintmax_t free;
263 uintmax_t available;
264};
265
Eric Fiselier833d6442016-09-15 22:27:07 +0000266enum class _LIBCPP_ENUM_VIS file_type : signed char
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000267{
268 none = 0,
269 not_found = -1,
270 regular = 1,
271 directory = 2,
272 symlink = 3,
273 block = 4,
274 character = 5,
275 fifo = 6,
276 socket = 7,
277 unknown = 8
278};
279
Eric Fiselier833d6442016-09-15 22:27:07 +0000280enum class _LIBCPP_ENUM_VIS perms : unsigned
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000281{
282 none = 0,
283
284 owner_read = 0400,
285 owner_write = 0200,
286 owner_exec = 0100,
287 owner_all = 0700,
288
289 group_read = 040,
290 group_write = 020,
291 group_exec = 010,
292 group_all = 070,
293
294 others_read = 04,
295 others_write = 02,
296 others_exec = 01,
297 others_all = 07,
298
299 all = 0777,
300
301 set_uid = 04000,
302 set_gid = 02000,
303 sticky_bit = 01000,
304 mask = 07777,
305 unknown = 0xFFFF,
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000306};
307
308_LIBCPP_INLINE_VISIBILITY
309inline _LIBCPP_CONSTEXPR perms operator&(perms _LHS, perms _RHS)
310{ return static_cast<perms>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }
311
312_LIBCPP_INLINE_VISIBILITY
313inline _LIBCPP_CONSTEXPR perms operator|(perms _LHS, perms _RHS)
314{ return static_cast<perms>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }
315
316_LIBCPP_INLINE_VISIBILITY
317inline _LIBCPP_CONSTEXPR perms operator^(perms _LHS, perms _RHS)
318{ return static_cast<perms>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }
319
320_LIBCPP_INLINE_VISIBILITY
321inline _LIBCPP_CONSTEXPR perms operator~(perms _LHS)
322{ return static_cast<perms>(~static_cast<unsigned>(_LHS)); }
323
324_LIBCPP_INLINE_VISIBILITY
325inline perms& operator&=(perms& _LHS, perms _RHS)
326{ return _LHS = _LHS & _RHS; }
327
328_LIBCPP_INLINE_VISIBILITY
329inline perms& operator|=(perms& _LHS, perms _RHS)
330{ return _LHS = _LHS | _RHS; }
331
332_LIBCPP_INLINE_VISIBILITY
333inline perms& operator^=(perms& _LHS, perms _RHS)
334{ return _LHS = _LHS ^ _RHS; }
335
Eric Fiselierf2c93732018-03-26 06:23:55 +0000336enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
337 replace = 1,
338 add = 2,
339 remove = 4,
340 nofollow = 8
341};
342
343_LIBCPP_INLINE_VISIBILITY
344inline _LIBCPP_CONSTEXPR perm_options operator&(perm_options _LHS, perm_options _RHS)
345{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }
346
347_LIBCPP_INLINE_VISIBILITY
348inline _LIBCPP_CONSTEXPR perm_options operator|(perm_options _LHS, perm_options _RHS)
349{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }
350
351_LIBCPP_INLINE_VISIBILITY
352inline _LIBCPP_CONSTEXPR perm_options operator^(perm_options _LHS, perm_options _RHS)
353{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }
354
355_LIBCPP_INLINE_VISIBILITY
356inline _LIBCPP_CONSTEXPR perm_options operator~(perm_options _LHS)
357{ return static_cast<perm_options>(~static_cast<unsigned>(_LHS)); }
358
359_LIBCPP_INLINE_VISIBILITY
360inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS)
361{ return _LHS = _LHS & _RHS; }
362
363_LIBCPP_INLINE_VISIBILITY
364inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS)
365{ return _LHS = _LHS | _RHS; }
366
367_LIBCPP_INLINE_VISIBILITY
368inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS)
369{ return _LHS = _LHS ^ _RHS; }
370
Eric Fiselier833d6442016-09-15 22:27:07 +0000371enum class _LIBCPP_ENUM_VIS copy_options : unsigned short
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000372{
373 none = 0,
374 skip_existing = 1,
375 overwrite_existing = 2,
376 update_existing = 4,
377 recursive = 8,
378 copy_symlinks = 16,
379 skip_symlinks = 32,
380 directories_only = 64,
381 create_symlinks = 128,
382 create_hard_links = 256,
383 __in_recursive_copy = 512,
384};
385
386_LIBCPP_INLINE_VISIBILITY
387inline _LIBCPP_CONSTEXPR copy_options operator&(copy_options _LHS, copy_options _RHS)
388{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) & static_cast<unsigned short>(_RHS)); }
389
390_LIBCPP_INLINE_VISIBILITY
391inline _LIBCPP_CONSTEXPR copy_options operator|(copy_options _LHS, copy_options _RHS)
392{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) | static_cast<unsigned short>(_RHS)); }
393
394_LIBCPP_INLINE_VISIBILITY
395inline _LIBCPP_CONSTEXPR copy_options operator^(copy_options _LHS, copy_options _RHS)
396{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^ static_cast<unsigned short>(_RHS)); }
397
398_LIBCPP_INLINE_VISIBILITY
399inline _LIBCPP_CONSTEXPR copy_options operator~(copy_options _LHS)
400{ return static_cast<copy_options>(~static_cast<unsigned short>(_LHS)); }
401
402_LIBCPP_INLINE_VISIBILITY
403inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS)
404{ return _LHS = _LHS & _RHS; }
405
406_LIBCPP_INLINE_VISIBILITY
407inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS)
408{ return _LHS = _LHS | _RHS; }
409
410_LIBCPP_INLINE_VISIBILITY
411inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS)
412{ return _LHS = _LHS ^ _RHS; }
413
414
Eric Fiselier833d6442016-09-15 22:27:07 +0000415enum class _LIBCPP_ENUM_VIS directory_options : unsigned char
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000416{
417 none = 0,
418 follow_directory_symlink = 1,
419 skip_permission_denied = 2
420};
421
422_LIBCPP_INLINE_VISIBILITY
423inline _LIBCPP_CONSTEXPR directory_options operator&(directory_options _LHS, directory_options _RHS)
424{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) & static_cast<unsigned char>(_RHS)); }
425
426_LIBCPP_INLINE_VISIBILITY
427inline _LIBCPP_CONSTEXPR directory_options operator|(directory_options _LHS, directory_options _RHS)
428{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) | static_cast<unsigned char>(_RHS)); }
429
430_LIBCPP_INLINE_VISIBILITY
431inline _LIBCPP_CONSTEXPR directory_options operator^(directory_options _LHS, directory_options _RHS)
432{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^ static_cast<unsigned char>(_RHS)); }
433
434_LIBCPP_INLINE_VISIBILITY
435inline _LIBCPP_CONSTEXPR directory_options operator~(directory_options _LHS)
436{ return static_cast<directory_options>(~static_cast<unsigned char>(_LHS)); }
437
438_LIBCPP_INLINE_VISIBILITY
439inline directory_options& operator&=(directory_options& _LHS, directory_options _RHS)
440{ return _LHS = _LHS & _RHS; }
441
442_LIBCPP_INLINE_VISIBILITY
443inline directory_options& operator|=(directory_options& _LHS, directory_options _RHS)
444{ return _LHS = _LHS | _RHS; }
445
446_LIBCPP_INLINE_VISIBILITY
447inline directory_options& operator^=(directory_options& _LHS, directory_options _RHS)
448{ return _LHS = _LHS ^ _RHS; }
449
450
451class _LIBCPP_TYPE_VIS file_status
452{
453public:
454 // constructors
455 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier7c7df642017-03-06 21:02:06 +0000456 file_status() _NOEXCEPT : file_status(file_type::none) {}
457 _LIBCPP_INLINE_VISIBILITY
458 explicit file_status(file_type __ft,
459 perms __prms = perms::unknown) _NOEXCEPT
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000460 : __ft_(__ft), __prms_(__prms)
461 {}
462
463 file_status(const file_status&) _NOEXCEPT = default;
464 file_status(file_status&&) _NOEXCEPT = default;
465
466 _LIBCPP_INLINE_VISIBILITY
467 ~file_status() {}
468
469 file_status& operator=(const file_status&) _NOEXCEPT = default;
470 file_status& operator=(file_status&&) _NOEXCEPT = default;
471
472 // observers
Louis Dionne4e7ffca2018-07-05 18:41:50 +0000473 _LIBCPP_ALWAYS_INLINE
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000474 file_type type() const _NOEXCEPT {
475 return __ft_;
476 }
477
Louis Dionne4e7ffca2018-07-05 18:41:50 +0000478 _LIBCPP_ALWAYS_INLINE
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000479 perms permissions() const _NOEXCEPT {
480 return __prms_;
481 }
482
483 // modifiers
Louis Dionne4e7ffca2018-07-05 18:41:50 +0000484 _LIBCPP_ALWAYS_INLINE
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000485 void type(file_type __ft) _NOEXCEPT {
486 __ft_ = __ft;
487 }
488
Louis Dionne4e7ffca2018-07-05 18:41:50 +0000489 _LIBCPP_ALWAYS_INLINE
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000490 void permissions(perms __p) _NOEXCEPT {
491 __prms_ = __p;
492 }
493private:
494 file_type __ft_;
495 perms __prms_;
496};
497
498class _LIBCPP_TYPE_VIS directory_entry;
499
500template <class _Tp> struct __can_convert_char {
501 static const bool value = false;
502};
Eric Fiselier113315b2016-08-28 21:26:01 +0000503template <class _Tp> struct __can_convert_char<const _Tp>
504 : public __can_convert_char<_Tp> {
505};
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000506template <> struct __can_convert_char<char> {
507 static const bool value = true;
508 using __char_type = char;
509};
510template <> struct __can_convert_char<wchar_t> {
511 static const bool value = true;
512 using __char_type = wchar_t;
513};
514template <> struct __can_convert_char<char16_t> {
515 static const bool value = true;
516 using __char_type = char16_t;
517};
518template <> struct __can_convert_char<char32_t> {
519 static const bool value = true;
520 using __char_type = char32_t;
521};
522
523template <class _ECharT>
524typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
525__is_separator(_ECharT __e) {
526 return __e == _ECharT('/');
527};
528
529struct _NullSentinal {};
530
531template <class _Tp>
532using _Void = void;
533
534template <class _Tp, class = void>
535struct __is_pathable_string : public false_type {};
536
537template <class _ECharT, class _Traits, class _Alloc>
538struct __is_pathable_string<basic_string<_ECharT, _Traits, _Alloc>,
539 _Void<typename __can_convert_char<_ECharT>::__char_type>>
540: public __can_convert_char<_ECharT>
541{
542 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
543 using _Base = __can_convert_char<_ECharT>;
544 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
545 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
546 static _ECharT __first_or_null(_Str const& __s) {
547 return __s.empty() ? _ECharT{} : __s[0];
548 }
549};
550
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000551
552template <class _ECharT, class _Traits>
553struct __is_pathable_string<basic_string_view<_ECharT, _Traits>,
554 _Void<typename __can_convert_char<_ECharT>::__char_type>>
555: public __can_convert_char<_ECharT>
556{
557 using _Str = basic_string_view<_ECharT, _Traits>;
558 using _Base = __can_convert_char<_ECharT>;
559 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
560 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
561 static _ECharT __first_or_null(_Str const& __s) {
562 return __s.empty() ? _ECharT{} : __s[0];
563 }
564};
565
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000566template <class _Source,
567 class _DS = typename decay<_Source>::type,
568 class _UnqualPtrType = typename remove_const<
569 typename remove_pointer<_DS>::type>::type,
570 bool _IsCharPtr = is_pointer<_DS>::value &&
571 __can_convert_char<_UnqualPtrType>::value
572 >
573struct __is_pathable_char_array : false_type {};
574
575template <class _Source, class _ECharT, class _UPtr>
576struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
577 : __can_convert_char<typename remove_const<_ECharT>::type>
578{
579 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
580
581 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
582 static _ECharT const* __range_end(const _ECharT* __b)
583 {
584 using _Iter = const _ECharT*;
585 const _ECharT __sentinal = _ECharT{};
586 _Iter __e = __b;
587 for (; *__e != __sentinal; ++__e)
588 ;
589 return __e;
590 }
591
592 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
593};
594
595template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value, class = void>
596struct __is_pathable_iter : false_type {};
597
598template <class _Iter>
599struct __is_pathable_iter<_Iter, true,
600 _Void<typename __can_convert_char<typename iterator_traits<_Iter>::value_type>::__char_type>>
601 : __can_convert_char<typename iterator_traits<_Iter>::value_type>
602{
603 using _ECharT = typename iterator_traits<_Iter>::value_type;
604 using _Base = __can_convert_char<_ECharT>;
605
606 static _Iter __range_begin(_Iter __b) { return __b; }
607 static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; }
608
609 static _ECharT __first_or_null(_Iter __b) { return *__b; }
610};
611
612template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
613 bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
614 bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value
615 >
616struct __is_pathable : false_type {
617 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
618};
619
620template <class _Tp>
621struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
622
623
624template <class _Tp>
625struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {};
626
627
628template <class _Tp>
629struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
630
631
632template <class _ECharT>
633struct _PathCVT {
634 static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible");
635
636 typedef __narrow_to_utf8<sizeof(_ECharT)*__CHAR_BIT__> _Narrower;
637
638 static void __append_range(string& __dest, _ECharT const* __b, _ECharT const* __e) {
639 _Narrower()(back_inserter(__dest), __b, __e);
640 }
641
642 template <class _Iter>
643 static void __append_range(string& __dest, _Iter __b, _Iter __e) {
644 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
645 if (__b == __e) return;
646 basic_string<_ECharT> __tmp(__b, __e);
647 _Narrower()(back_inserter(__dest), __tmp.data(),
648 __tmp.data() + __tmp.length());
649 }
650
651 template <class _Iter>
652 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
653 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
654 const _ECharT __sentinal = _ECharT{};
655 if (*__b == __sentinal) return;
656 basic_string<_ECharT> __tmp;
657 for (; *__b != __sentinal; ++__b)
658 __tmp.push_back(*__b);
659 _Narrower()(back_inserter(__dest), __tmp.data(),
660 __tmp.data() + __tmp.length());
661 }
662
663 template <class _Source>
664 static void __append_source(string& __dest, _Source const& __s)
665 {
666 using _Traits = __is_pathable<_Source>;
667 __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
668 }
669};
670
671template <>
672struct _PathCVT<char> {
Eric Fiselierad1a12c2016-10-30 23:53:50 +0000673
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000674 template <class _Iter>
Eric Fiselier026d38e2016-10-31 02:46:25 +0000675 static typename enable_if<
676 __is_exactly_input_iterator<_Iter>::value
677 >::type __append_range(string& __dest, _Iter __b, _Iter __e) {
678 for (; __b != __e; ++__b)
679 __dest.push_back(*__b);
680 }
681
682 template <class _Iter>
683 static typename enable_if<
684 __is_forward_iterator<_Iter>::value
685 >::type __append_range(string& __dest, _Iter __b, _Iter __e) {
686 __dest.__append_forward_unsafe(__b, __e);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000687 }
688
689 template <class _Iter>
690 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
691 const char __sentinal = char{};
692 for (; *__b != __sentinal; ++__b)
693 __dest.push_back(*__b);
694 }
695
696 template <class _Source>
697 static void __append_source(string& __dest, _Source const& __s)
698 {
699 using _Traits = __is_pathable<_Source>;
Eric Fiselierad1a12c2016-10-30 23:53:50 +0000700 __append_range(__dest, _Traits::__range_begin(__s),
701 _Traits::__range_end(__s));
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000702 }
703};
704
705
706class _LIBCPP_TYPE_VIS path
707{
708 template <class _SourceOrIter, class _Tp = path&>
709 using _EnableIfPathable = typename
710 enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
711
712 template <class _Tp>
713 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
714
715 template <class _Tp>
716 using _SourceCVT = _PathCVT<_SourceChar<_Tp>>;
717
718public:
719 typedef char value_type;
720 typedef basic_string<value_type> string_type;
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000721 typedef _VSTD::string_view __string_view;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000722 static _LIBCPP_CONSTEXPR value_type preferred_separator = '/';
723
Eric Fiseliere96d6a12018-04-02 23:35:24 +0000724 enum class _LIBCPP_ENUM_VIS format : unsigned char {
725 auto_format,
726 native_format,
727 generic_format
728 };
729
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000730 // constructors and destructor
731 _LIBCPP_INLINE_VISIBILITY path() _NOEXCEPT {}
732 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
733 _LIBCPP_INLINE_VISIBILITY path(path&& __p) _NOEXCEPT : __pn_(_VSTD::move(__p.__pn_)) {}
734
735 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere96d6a12018-04-02 23:35:24 +0000736 path(string_type&& __s, format = format::auto_format) _NOEXCEPT
737 : __pn_(_VSTD::move(__s)) {}
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000738
739 template <
740 class _Source,
741 class = _EnableIfPathable<_Source, void>
742 >
Eric Fiseliere96d6a12018-04-02 23:35:24 +0000743 path(const _Source& __src, format = format::auto_format) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000744 _SourceCVT<_Source>::__append_source(__pn_, __src);
745 }
746
747 template <class _InputIt>
Eric Fiseliere96d6a12018-04-02 23:35:24 +0000748 path(_InputIt __first, _InputIt __last, format = format::auto_format) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000749 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
750 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
751 }
752
753 // TODO Implement locale conversions.
754 template <class _Source,
755 class = _EnableIfPathable<_Source, void>
756 >
Eric Fiseliere96d6a12018-04-02 23:35:24 +0000757 path(const _Source& __src, const locale& __loc,
758 format = format::auto_format);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000759 template <class _InputIt>
Eric Fiseliere96d6a12018-04-02 23:35:24 +0000760 path(_InputIt __first, _InputIt _last, const locale& __loc,
761 format = format::auto_format);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000762
763 _LIBCPP_INLINE_VISIBILITY
764 ~path() = default;
765
766 // assignments
767 _LIBCPP_INLINE_VISIBILITY
768 path& operator=(const path& __p) {
769 __pn_ = __p.__pn_;
770 return *this;
771 }
772
773 _LIBCPP_INLINE_VISIBILITY
774 path& operator=(path&& __p) _NOEXCEPT {
775 __pn_ = _VSTD::move(__p.__pn_);
776 return *this;
777 }
778
Eric Fiselierf2b48892017-01-18 05:48:55 +0000779 template <class = void>
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000780 _LIBCPP_INLINE_VISIBILITY
781 path& operator=(string_type&& __s) _NOEXCEPT {
782 __pn_ = _VSTD::move(__s);
783 return *this;
784 }
785
786 _LIBCPP_INLINE_VISIBILITY
787 path& assign(string_type&& __s) _NOEXCEPT {
788 __pn_ = _VSTD::move(__s);
789 return *this;
790 }
791
792 template <class _Source>
793 _LIBCPP_INLINE_VISIBILITY
794 _EnableIfPathable<_Source>
795 operator=(const _Source& __src)
796 { return this->assign(__src); }
797
798
799 template <class _Source>
800 _EnableIfPathable<_Source>
801 assign(const _Source& __src) {
802 __pn_.clear();
803 _SourceCVT<_Source>::__append_source(__pn_, __src);
804 return *this;
805 }
806
807 template <class _InputIt>
808 path& assign(_InputIt __first, _InputIt __last) {
809 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
810 __pn_.clear();
811 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
812 return *this;
813 }
814
815private:
816 template <class _ECharT>
Eric Fiselier1e34c762018-04-02 23:03:41 +0000817 static bool __source_is_absolute(_ECharT __first_or_null) {
818 return __is_separator(__first_or_null);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000819 }
820
821public:
822 // appends
823 path& operator/=(const path& __p) {
Eric Fiselier1e34c762018-04-02 23:03:41 +0000824 if (__p.is_absolute()) {
825 __pn_ = __p.__pn_;
826 return *this;
827 }
828 if (has_filename())
829 __pn_ += preferred_separator;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000830 __pn_ += __p.native();
831 return *this;
832 }
833
Eric Fiselier1e34c762018-04-02 23:03:41 +0000834 // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
835 // is known at compile time to be "/' since the user almost certainly intended
836 // to append a separator instead of overwriting the path with "/"
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000837 template <class _Source>
838 _LIBCPP_INLINE_VISIBILITY
839 _EnableIfPathable<_Source>
840 operator/=(const _Source& __src) {
841 return this->append(__src);
842 }
843
844 template <class _Source>
845 _EnableIfPathable<_Source>
846 append(const _Source& __src) {
847 using _Traits = __is_pathable<_Source>;
848 using _CVT = _PathCVT<_SourceChar<_Source>>;
Eric Fiselier1e34c762018-04-02 23:03:41 +0000849 if (__source_is_absolute(_Traits::__first_or_null(__src)))
850 __pn_.clear();
851 else if (has_filename())
852 __pn_ += preferred_separator;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000853 _CVT::__append_source(__pn_, __src);
854 return *this;
855 }
856
857 template <class _InputIt>
858 path& append(_InputIt __first, _InputIt __last) {
859 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
860 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
861 using _CVT = _PathCVT<_ItVal>;
Eric Fiselier1e34c762018-04-02 23:03:41 +0000862 if (__first != __last && __source_is_absolute(*__first))
863 __pn_.clear();
864 else if (has_filename())
865 __pn_ += preferred_separator;
866 _CVT::__append_range(__pn_, __first, __last);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000867 return *this;
868 }
869
870 // concatenation
871 _LIBCPP_INLINE_VISIBILITY
872 path& operator+=(const path& __x) {
873 __pn_ += __x.__pn_;
874 return *this;
875 }
876
877 _LIBCPP_INLINE_VISIBILITY
878 path& operator+=(const string_type& __x) {
879 __pn_ += __x;
880 return *this;
881 }
882
883 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000884 path& operator+=(__string_view __x) {
885 __pn_ += __x;
886 return *this;
887 }
888
889 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000890 path& operator+=(const value_type* __x) {
891 __pn_ += __x;
892 return *this;
893 }
894
895 _LIBCPP_INLINE_VISIBILITY
896 path& operator+=(value_type __x) {
897 __pn_ += __x;
898 return *this;
899 }
900
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000901 template <class _ECharT>
902 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
903 operator+=(_ECharT __x)
904 {
905 basic_string<_ECharT> __tmp;
906 __tmp += __x;
907 _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
908 return *this;
909 }
910
911 template <class _Source>
912 _EnableIfPathable<_Source>
913 operator+=(const _Source& __x) {
914 return this->concat(__x);
915 }
916
917 template <class _Source>
918 _EnableIfPathable<_Source>
919 concat(const _Source& __x) {
920 _SourceCVT<_Source>::__append_source(__pn_, __x);
921 return *this;
922 }
923
924 template <class _InputIt>
925 path& concat(_InputIt __first, _InputIt __last) {
926 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
927 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
928 return *this;
929 }
930
931 // modifiers
932 _LIBCPP_INLINE_VISIBILITY
933 void clear() _NOEXCEPT {
934 __pn_.clear();
935 }
936
937 path& make_preferred() { return *this; }
Eric Fiselier620a9a52016-10-15 22:37:42 +0000938
939 _LIBCPP_INLINE_VISIBILITY
940 path& remove_filename() {
Eric Fiselier1e34c762018-04-02 23:03:41 +0000941 auto __fname = __filename();
942 if (!__fname.empty())
943 __pn_.erase(__fname.data() - __pn_.data());
Eric Fiselier620a9a52016-10-15 22:37:42 +0000944 return *this;
945 }
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000946
947 path& replace_filename(const path& __replacement) {
948 remove_filename();
949 return (*this /= __replacement);
950 }
951
952 path& replace_extension(const path& __replacement = path());
953
954 _LIBCPP_INLINE_VISIBILITY
955 void swap(path& __rhs) _NOEXCEPT {
956 __pn_.swap(__rhs.__pn_);
957 }
958
Eric Fiselier1e34c762018-04-02 23:03:41 +0000959 // private helper to allow reserving memory in the path
960 _LIBCPP_INLINE_VISIBILITY
961 void __reserve(size_t __s) { __pn_.reserve(__s); }
962
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000963 // native format observers
964 _LIBCPP_INLINE_VISIBILITY
965 const string_type& native() const _NOEXCEPT {
966 return __pn_;
967 }
968
969 _LIBCPP_INLINE_VISIBILITY
970 const value_type* c_str() const _NOEXCEPT { return __pn_.c_str(); }
971
972 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
973
974 template <class _ECharT, class _Traits = char_traits<_ECharT>,
975 class _Allocator = allocator<_ECharT> >
976 basic_string<_ECharT, _Traits, _Allocator>
977 string(const _Allocator& __a = _Allocator()) const {
978 using _CVT = __widen_from_utf8<sizeof(_ECharT)*__CHAR_BIT__>;
979 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
980 _Str __s(__a);
981 __s.reserve(__pn_.size());
982 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
983 return __s;
984 }
985
986 _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
987 _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const { return string<wchar_t>(); }
988 _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
989 _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { return string<char16_t>(); }
990 _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { return string<char32_t>(); }
991
992 // generic format observers
993 template <class _ECharT, class _Traits = char_traits<_ECharT>,
994 class _Allocator = allocator<_ECharT>
995 >
996 basic_string<_ECharT, _Traits, _Allocator>
997 generic_string(const _Allocator& __a = _Allocator()) const {
998 return string<_ECharT, _Traits, _Allocator>(__a);
999 }
1000
1001 std::string generic_string() const { return __pn_; }
1002 std::wstring generic_wstring() const { return string<wchar_t>(); }
1003 std::string generic_u8string() const { return __pn_; }
1004 std::u16string generic_u16string() const { return string<char16_t>(); }
1005 std::u32string generic_u32string() const { return string<char32_t>(); }
1006
1007private:
Saleem Abdulrasool52241cb2017-01-30 03:58:26 +00001008 int __compare(__string_view) const;
1009 __string_view __root_name() const;
1010 __string_view __root_directory() const;
1011 __string_view __root_path_raw() const;
1012 __string_view __relative_path() const;
1013 __string_view __parent_path() const;
1014 __string_view __filename() const;
1015 __string_view __stem() const;
1016 __string_view __extension() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001017
1018public:
1019 // compare
Eric Fiselier2645dbe2016-07-23 03:10:56 +00001020 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const _NOEXCEPT { return __compare(__p.__pn_);}
1021 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); }
1022 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001023 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { return __compare(__s); }
1024
1025 // decomposition
Eric Fiselier2645dbe2016-07-23 03:10:56 +00001026 _LIBCPP_INLINE_VISIBILITY path root_name() const { return string_type(__root_name()); }
1027 _LIBCPP_INLINE_VISIBILITY path root_directory() const { return string_type(__root_directory()); }
1028 _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(string_type(__root_directory())); }
1029 _LIBCPP_INLINE_VISIBILITY path relative_path() const { return string_type(__relative_path()); }
1030 _LIBCPP_INLINE_VISIBILITY path parent_path() const { return string_type(__parent_path()); }
1031 _LIBCPP_INLINE_VISIBILITY path filename() const { return string_type(__filename()); }
1032 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem());}
1033 _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001034
1035 // query
Marshall Clowbc6989b2017-11-16 05:48:32 +00001036 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1037 bool empty() const _NOEXCEPT { return __pn_.empty(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001038
1039 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); }
1040 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); }
Eric Fiselier620a9a52016-10-15 22:37:42 +00001041 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !__root_path_raw().empty(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001042 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { return !__relative_path().empty(); }
1043 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { return !__parent_path().empty(); }
1044 _LIBCPP_INLINE_VISIBILITY bool has_filename() const { return !__filename().empty(); }
1045 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
1046 _LIBCPP_INLINE_VISIBILITY bool has_extension() const { return !__extension().empty(); }
1047
1048 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { return has_root_directory(); }
1049 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
1050
Eric Fiselier1e34c762018-04-02 23:03:41 +00001051 // relative paths
1052 path lexically_normal() const;
1053 path lexically_relative(const path& __base) const;
1054
1055 _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
1056 path __result = this->lexically_relative(__base);
1057 if (__result.native().empty())
1058 return *this;
1059 return __result;
1060 }
1061
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001062 // iterators
1063 class _LIBCPP_TYPE_VIS iterator;
1064 typedef iterator const_iterator;
1065
Saleem Abdulrasool52241cb2017-01-30 03:58:26 +00001066 iterator begin() const;
1067 iterator end() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001068
Eric Fiselier0b47a652018-02-04 03:10:53 +00001069
1070 template <class _CharT, class _Traits>
1071 _LIBCPP_INLINE_VISIBILITY
1072 friend typename enable_if<is_same<_CharT, char>::value &&
1073 is_same<_Traits, char_traits<char>>::value,
1074 basic_ostream<_CharT, _Traits>&
1075 >::type
1076 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1077 __os << std::__quoted(__p.native());
1078 return __os;
1079 }
1080
1081 template <class _CharT, class _Traits>
1082 _LIBCPP_INLINE_VISIBILITY
1083 friend typename enable_if<!is_same<_CharT, char>::value ||
1084 !is_same<_Traits, char_traits<char>>::value,
1085 basic_ostream<_CharT, _Traits>&
1086 >::type
1087 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1088 __os << std::__quoted(__p.string<_CharT, _Traits>());
1089 return __os;
1090 }
1091
1092 template <class _CharT, class _Traits>
1093 _LIBCPP_INLINE_VISIBILITY
1094 friend basic_istream<_CharT, _Traits>&
1095 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
1096 {
1097 basic_string<_CharT, _Traits> __tmp;
1098 __is >> __quoted(__tmp);
1099 __p = __tmp;
1100 return __is;
1101 }
1102
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001103private:
1104 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2645dbe2016-07-23 03:10:56 +00001105 path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001106 string_type __pn_;
1107};
1108
Louis Dionne4e7ffca2018-07-05 18:41:50 +00001109inline _LIBCPP_ALWAYS_INLINE
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001110void swap(path& __lhs, path& __rhs) _NOEXCEPT {
1111 __lhs.swap(__rhs);
1112}
1113
1114_LIBCPP_FUNC_VIS
1115size_t hash_value(const path& __p) _NOEXCEPT;
1116
1117inline _LIBCPP_INLINE_VISIBILITY
1118bool operator==(const path& __lhs, const path& __rhs) _NOEXCEPT
1119{ return __lhs.compare(__rhs) == 0; }
1120
1121inline _LIBCPP_INLINE_VISIBILITY
1122bool operator!=(const path& __lhs, const path& __rhs) _NOEXCEPT
1123{ return __lhs.compare(__rhs) != 0; }
1124
1125inline _LIBCPP_INLINE_VISIBILITY
1126bool operator<(const path& __lhs, const path& __rhs) _NOEXCEPT
1127{ return __lhs.compare(__rhs) < 0; }
1128
1129inline _LIBCPP_INLINE_VISIBILITY
1130bool operator<=(const path& __lhs, const path& __rhs) _NOEXCEPT
1131{ return __lhs.compare(__rhs) <= 0; }
1132
1133inline _LIBCPP_INLINE_VISIBILITY
1134bool operator>(const path& __lhs, const path& __rhs) _NOEXCEPT
1135{ return __lhs.compare(__rhs) > 0; }
1136
1137inline _LIBCPP_INLINE_VISIBILITY
1138bool operator>=(const path& __lhs, const path& __rhs) _NOEXCEPT
1139{ return __lhs.compare(__rhs) >= 0; }
1140
1141inline _LIBCPP_INLINE_VISIBILITY
1142path operator/(const path& __lhs, const path& __rhs) {
David Bolvansky9887da82018-05-09 18:57:17 +00001143 path __result(__lhs);
1144 __result /= __rhs;
1145 return __result;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001146}
1147
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001148template <class _Source>
1149_LIBCPP_INLINE_VISIBILITY
1150typename enable_if<__is_pathable<_Source>::value, path>::type
1151u8path(const _Source& __s){
1152 static_assert(is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1153 "u8path(Source const&) requires Source have a character type of type 'char'");
1154 return path(__s);
1155}
1156
1157template <class _InputIt>
1158_LIBCPP_INLINE_VISIBILITY
1159typename enable_if<__is_pathable<_InputIt>::value, path>::type
1160u8path(_InputIt __f, _InputIt __l) {
1161 static_assert(is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1162 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1163 return path(__f, __l);
1164}
1165
1166class _LIBCPP_TYPE_VIS path::iterator
1167{
1168public:
1169 typedef bidirectional_iterator_tag iterator_category;
Eric Fiselier08673732017-04-04 01:05:59 +00001170
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001171 typedef path value_type;
1172 typedef std::ptrdiff_t difference_type;
1173 typedef const path* pointer;
1174 typedef const path& reference;
Eric Fiselier706e2c72017-04-13 02:54:13 +00001175
1176 typedef void __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001177public:
1178 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier271a19e2016-10-30 23:30:38 +00001179 iterator() : __stashed_elem_(), __path_ptr_(nullptr),
1180 __entry_(), __state_(__singular) {}
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001181
1182 iterator(const iterator&) = default;
1183 ~iterator() = default;
1184
1185 iterator& operator=(const iterator&) = default;
1186
1187 _LIBCPP_INLINE_VISIBILITY
1188 reference operator*() const {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001189 return __stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001190 }
1191
1192 _LIBCPP_INLINE_VISIBILITY
1193 pointer operator->() const {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001194 return &__stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001195 }
1196
1197 _LIBCPP_INLINE_VISIBILITY
1198 iterator& operator++() {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001199 _LIBCPP_ASSERT(__state_ != __singular,
1200 "attempting to increment a singular iterator");
1201 _LIBCPP_ASSERT(__state_ != __at_end,
1202 "attempting to increment the end iterator");
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001203 return __increment();
1204 }
1205
1206 _LIBCPP_INLINE_VISIBILITY
1207 iterator operator++(int) {
1208 iterator __it(*this);
1209 this->operator++();
1210 return __it;
1211 }
1212
1213 _LIBCPP_INLINE_VISIBILITY
1214 iterator& operator--() {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001215 _LIBCPP_ASSERT(__state_ != __singular,
1216 "attempting to decrement a singular iterator");
1217 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
1218 "attempting to decrement the begin iterator");
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001219 return __decrement();
1220 }
1221
1222 _LIBCPP_INLINE_VISIBILITY
1223 iterator operator--(int) {
1224 iterator __it(*this);
1225 this->operator--();
1226 return __it;
1227 }
1228
1229private:
1230 friend class path;
Eric Fiselier03f7d102016-09-16 00:07:16 +00001231
Eric Fiselier271a19e2016-10-30 23:30:38 +00001232 static constexpr unsigned char __singular = 0;
1233 static constexpr unsigned char __at_end = 6;
1234
Eric Fiselier03f7d102016-09-16 00:07:16 +00001235 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001236 friend bool operator==(const iterator&, const iterator&);
1237
Saleem Abdulrasool52241cb2017-01-30 03:58:26 +00001238 iterator& __increment();
1239 iterator& __decrement();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001240
Eric Fiselier271a19e2016-10-30 23:30:38 +00001241 path __stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001242 const path* __path_ptr_;
Eric Fiselier271a19e2016-10-30 23:30:38 +00001243 path::__string_view __entry_;
1244 unsigned char __state_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001245};
1246
1247inline _LIBCPP_INLINE_VISIBILITY
1248bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) {
1249 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
Eric Fiselier271a19e2016-10-30 23:30:38 +00001250 __lhs.__entry_.data() == __rhs.__entry_.data();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001251}
1252
1253inline _LIBCPP_INLINE_VISIBILITY
1254bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) {
1255 return !(__lhs == __rhs);
1256}
1257
1258class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error
1259{
1260public:
1261 _LIBCPP_INLINE_VISIBILITY
1262 filesystem_error(const string& __what, error_code __ec)
1263 : system_error(__ec, __what),
1264 __paths_(make_shared<_Storage>(path(), path()))
1265 {}
1266
1267 _LIBCPP_INLINE_VISIBILITY
1268 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1269 : system_error(__ec, __what),
1270 __paths_(make_shared<_Storage>(__p1, path()))
1271 {}
1272
1273 _LIBCPP_INLINE_VISIBILITY
1274 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1275 error_code __ec)
1276 : system_error(__ec, __what),
1277 __paths_(make_shared<_Storage>(__p1, __p2))
1278 {}
1279
1280 _LIBCPP_INLINE_VISIBILITY
1281 const path& path1() const _NOEXCEPT {
1282 return __paths_->first;
1283 }
1284
1285 _LIBCPP_INLINE_VISIBILITY
1286 const path& path2() const _NOEXCEPT {
1287 return __paths_->second;
1288 }
1289
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001290 ~filesystem_error() override; // key function
1291
1292 // TODO(ericwf): Create a custom error message.
1293 //const char* what() const _NOEXCEPT;
1294
1295private:
1296 typedef pair<path, path> _Storage;
1297 shared_ptr<_Storage> __paths_;
1298};
1299
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001300template <class... _Args>
Louis Dionne4e7ffca2018-07-05 18:41:50 +00001301_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00001302#ifndef _LIBCPP_NO_EXCEPTIONS
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001303void __throw_filesystem_error(_Args && ...__args)
1304{
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001305 throw filesystem_error(std::forward<_Args>(__args)...);
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001306}
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00001307#else
1308void __throw_filesystem_error(_Args&&...)
1309{
1310 _VSTD::abort();
1311}
1312#endif
1313
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001314
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001315// operational functions
1316
1317_LIBCPP_FUNC_VIS
Eric Fiselier1e34c762018-04-02 23:03:41 +00001318path __absolute(const path&, error_code *__ec=nullptr);
1319_LIBCPP_FUNC_VIS
1320path __canonical(const path&, error_code *__ec=nullptr);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001321_LIBCPP_FUNC_VIS
1322void __copy(const path& __from, const path& __to, copy_options __opt,
1323 error_code *__ec=nullptr);
1324_LIBCPP_FUNC_VIS
1325bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1326 error_code *__ec=nullptr);
1327_LIBCPP_FUNC_VIS
1328void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1329 error_code *__ec=nullptr);
1330_LIBCPP_FUNC_VIS
1331bool __create_directories(const path& p, error_code *ec=nullptr);
1332_LIBCPP_FUNC_VIS
1333bool __create_directory(const path& p, error_code *ec=nullptr);
1334_LIBCPP_FUNC_VIS
1335bool __create_directory(const path& p, const path & attributes,
1336 error_code *ec=nullptr);
1337_LIBCPP_FUNC_VIS
1338void __create_directory_symlink(const path& __to, const path& __new_symlink,
1339 error_code *__ec=nullptr);
1340_LIBCPP_FUNC_VIS
1341void __create_hard_link(const path& __to, const path& __new_hard_link,
1342 error_code *__ec=nullptr);
1343_LIBCPP_FUNC_VIS
1344void __create_symlink(const path& __to, const path& __new_symlink,
1345 error_code *__ec=nullptr);
1346_LIBCPP_FUNC_VIS
1347path __current_path(error_code *__ec=nullptr);
1348_LIBCPP_FUNC_VIS
1349void __current_path(const path&, error_code *__ec=nullptr);
1350_LIBCPP_FUNC_VIS
1351bool __equivalent(const path&, const path&, error_code *__ec=nullptr);
1352_LIBCPP_FUNC_VIS
1353uintmax_t __file_size(const path&, error_code *__ec=nullptr);
1354_LIBCPP_FUNC_VIS
1355uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr);
1356_LIBCPP_FUNC_VIS
1357bool __fs_is_empty(const path& p, error_code *ec=nullptr);
1358_LIBCPP_FUNC_VIS
1359file_time_type __last_write_time(const path& p, error_code *ec=nullptr);
1360_LIBCPP_FUNC_VIS
1361void __last_write_time(const path& p, file_time_type new_time,
1362 error_code *ec=nullptr);
1363_LIBCPP_FUNC_VIS
Eric Fiselierf2c93732018-03-26 06:23:55 +00001364void __permissions(const path&, perms, perm_options, error_code* = nullptr);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001365_LIBCPP_FUNC_VIS
1366path __read_symlink(const path& p, error_code *ec=nullptr);
1367_LIBCPP_FUNC_VIS
1368bool __remove(const path& p, error_code *ec=nullptr);
1369_LIBCPP_FUNC_VIS
1370uintmax_t __remove_all(const path& p, error_code *ec=nullptr);
1371_LIBCPP_FUNC_VIS
1372void __rename(const path& from, const path& to, error_code *ec=nullptr);
1373_LIBCPP_FUNC_VIS
1374void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr);
1375_LIBCPP_FUNC_VIS
1376space_info __space(const path&, error_code *__ec=nullptr);
1377_LIBCPP_FUNC_VIS
1378file_status __status(const path&, error_code *__ec=nullptr);
1379_LIBCPP_FUNC_VIS
1380file_status __symlink_status(const path&, error_code *__ec=nullptr);
1381_LIBCPP_FUNC_VIS
1382path __system_complete(const path&, error_code *__ec=nullptr);
1383_LIBCPP_FUNC_VIS
1384path __temp_directory_path(error_code *__ec=nullptr);
Eric Fiselier1e34c762018-04-02 23:03:41 +00001385_LIBCPP_FUNC_VIS
1386path __weakly_canonical(path const& __p, error_code *__ec=nullptr);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001387
1388inline _LIBCPP_INLINE_VISIBILITY
1389path current_path() {
1390 return __current_path();
1391}
1392
1393inline _LIBCPP_INLINE_VISIBILITY
1394path current_path(error_code& __ec) {
1395 return __current_path(&__ec);
1396}
1397
1398inline _LIBCPP_INLINE_VISIBILITY
1399void current_path(const path& __p) {
1400 __current_path(__p);
1401}
1402
1403inline _LIBCPP_INLINE_VISIBILITY
1404void current_path(const path& __p, error_code& __ec) _NOEXCEPT {
1405 __current_path(__p, &__ec);
1406}
1407
Eric Fiselier1e34c762018-04-02 23:03:41 +00001408inline _LIBCPP_INLINE_VISIBILITY
1409path absolute(const path& __p) {
1410 return __absolute(__p);
1411}
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001412
1413inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1e34c762018-04-02 23:03:41 +00001414path absolute(const path& __p, error_code &__ec) {
1415 return __absolute(__p, &__ec);
1416}
1417
1418inline _LIBCPP_INLINE_VISIBILITY
1419path canonical(const path& __p) {
1420 return __canonical(__p);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001421}
1422
1423inline _LIBCPP_INLINE_VISIBILITY
1424path canonical(const path& __p, error_code& __ec) {
Eric Fiselier1e34c762018-04-02 23:03:41 +00001425 return __canonical(__p, &__ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001426}
1427
1428inline _LIBCPP_INLINE_VISIBILITY
1429void copy(const path& __from, const path& __to) {
1430 __copy(__from, __to, copy_options::none);
1431}
1432
1433inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001434void copy(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001435 __copy(__from, __to, copy_options::none, &__ec);
1436}
1437
1438inline _LIBCPP_INLINE_VISIBILITY
1439void copy(const path& __from, const path& __to, copy_options __opt) {
1440 __copy(__from, __to, __opt);
1441}
1442
1443inline _LIBCPP_INLINE_VISIBILITY
1444void copy(const path& __from, const path& __to,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001445 copy_options __opt, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001446 __copy(__from, __to, __opt, &__ec);
1447}
1448
1449inline _LIBCPP_INLINE_VISIBILITY
1450bool copy_file(const path& __from, const path& __to) {
1451 return __copy_file(__from, __to, copy_options::none);
1452}
1453
1454inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001455bool copy_file(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001456 return __copy_file(__from, __to, copy_options::none, &__ec);
1457}
1458
1459inline _LIBCPP_INLINE_VISIBILITY
1460bool copy_file(const path& __from, const path& __to, copy_options __opt) {
1461 return __copy_file(__from, __to, __opt);
1462}
1463
1464inline _LIBCPP_INLINE_VISIBILITY
1465bool copy_file(const path& __from, const path& __to,
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001466 copy_options __opt, error_code& __ec){
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001467 return __copy_file(__from, __to, __opt, &__ec);
1468}
1469
1470inline _LIBCPP_INLINE_VISIBILITY
1471void copy_symlink(const path& __existing, const path& __new) {
1472 __copy_symlink(__existing, __new);
1473}
1474
1475inline _LIBCPP_INLINE_VISIBILITY
1476void copy_symlink(const path& __ext, const path& __new, error_code& __ec) _NOEXCEPT {
1477 __copy_symlink(__ext, __new, &__ec);
1478}
1479
1480inline _LIBCPP_INLINE_VISIBILITY
1481bool create_directories(const path& __p) {
1482 return __create_directories(__p);
1483}
1484
1485inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001486bool create_directories(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001487 return __create_directories(__p, &__ec);
1488}
1489
1490inline _LIBCPP_INLINE_VISIBILITY
1491bool create_directory(const path& __p) {
1492 return __create_directory(__p);
1493}
1494
1495inline _LIBCPP_INLINE_VISIBILITY
1496bool create_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1497 return __create_directory(__p, &__ec);
1498}
1499
1500inline _LIBCPP_INLINE_VISIBILITY
1501bool create_directory(const path& __p, const path& __attrs) {
1502 return __create_directory(__p, __attrs);
1503}
1504
1505inline _LIBCPP_INLINE_VISIBILITY
1506bool create_directory(const path& __p, const path& __attrs, error_code& __ec) _NOEXCEPT {
1507 return __create_directory(__p, __attrs, &__ec);
1508}
1509
1510inline _LIBCPP_INLINE_VISIBILITY
1511void create_directory_symlink(const path& __to, const path& __new) {
1512 __create_directory_symlink(__to, __new);
1513}
1514
1515inline _LIBCPP_INLINE_VISIBILITY
1516void create_directory_symlink(const path& __to, const path& __new,
1517 error_code& __ec) _NOEXCEPT {
1518 __create_directory_symlink(__to, __new, &__ec);
1519}
1520
1521inline _LIBCPP_INLINE_VISIBILITY
1522void create_hard_link(const path& __to, const path& __new) {
1523 __create_hard_link(__to, __new);
1524}
1525
1526inline _LIBCPP_INLINE_VISIBILITY
1527void create_hard_link(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
1528 __create_hard_link(__to, __new, &__ec);
1529}
1530
1531inline _LIBCPP_INLINE_VISIBILITY
1532void create_symlink(const path& __to, const path& __new) {
1533 __create_symlink(__to, __new);
1534}
1535
1536inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1e34c762018-04-02 23:03:41 +00001537void create_symlink(const path& __to, const path& __new,
1538 error_code& __ec) _NOEXCEPT {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001539 return __create_symlink(__to, __new, &__ec);
1540}
1541
1542inline _LIBCPP_INLINE_VISIBILITY
1543bool status_known(file_status __s) _NOEXCEPT {
1544 return __s.type() != file_type::none;
1545}
1546
1547inline _LIBCPP_INLINE_VISIBILITY
1548bool exists(file_status __s) _NOEXCEPT {
1549 return status_known(__s) && __s.type() != file_type::not_found;
1550}
1551
1552inline _LIBCPP_INLINE_VISIBILITY
1553bool exists(const path& __p) {
1554 return exists(__status(__p));
1555}
1556
1557inline _LIBCPP_INLINE_VISIBILITY
1558bool exists(const path& __p, error_code& __ec) _NOEXCEPT {
Eric Fiselier756a6bd2016-06-21 22:11:16 +00001559 auto __s = __status(__p, &__ec);
1560 if (status_known(__s)) __ec.clear();
1561 return exists(__s);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001562}
1563
1564inline _LIBCPP_INLINE_VISIBILITY
1565bool equivalent(const path& __p1, const path& __p2) {
1566 return __equivalent(__p1, __p2);
1567}
1568
1569inline _LIBCPP_INLINE_VISIBILITY
1570bool equivalent(const path& __p1, const path& __p2, error_code& __ec) _NOEXCEPT {
1571 return __equivalent(__p1, __p2, &__ec);
1572}
1573
1574inline _LIBCPP_INLINE_VISIBILITY
1575uintmax_t file_size(const path& __p) {
1576 return __file_size(__p);
1577}
1578
1579inline _LIBCPP_INLINE_VISIBILITY
1580uintmax_t file_size(const path& __p, error_code& __ec) _NOEXCEPT {
1581 return __file_size(__p, &__ec);
1582}
1583
1584inline _LIBCPP_INLINE_VISIBILITY
1585uintmax_t hard_link_count(const path& __p) {
1586 return __hard_link_count(__p);
1587}
1588
1589inline _LIBCPP_INLINE_VISIBILITY
1590uintmax_t hard_link_count(const path& __p, error_code& __ec) _NOEXCEPT {
1591 return __hard_link_count(__p, &__ec);
1592}
1593
1594inline _LIBCPP_INLINE_VISIBILITY
1595bool is_block_file(file_status __s) _NOEXCEPT {
1596 return __s.type() == file_type::block;
1597}
1598
1599inline _LIBCPP_INLINE_VISIBILITY
1600bool is_block_file(const path& __p) {
1601 return is_block_file(__status(__p));
1602}
1603
1604inline _LIBCPP_INLINE_VISIBILITY
1605bool is_block_file(const path& __p, error_code& __ec) _NOEXCEPT {
1606 return is_block_file(__status(__p, &__ec));
1607}
1608
1609inline _LIBCPP_INLINE_VISIBILITY
1610bool is_character_file(file_status __s) _NOEXCEPT {
1611 return __s.type() == file_type::character;
1612}
1613
1614inline _LIBCPP_INLINE_VISIBILITY
1615bool is_character_file(const path& __p) {
1616 return is_character_file(__status(__p));
1617}
1618
1619inline _LIBCPP_INLINE_VISIBILITY
1620bool is_character_file(const path& __p, error_code& __ec) _NOEXCEPT {
1621 return is_character_file(__status(__p, &__ec));
1622}
1623
1624inline _LIBCPP_INLINE_VISIBILITY
1625bool is_directory(file_status __s) _NOEXCEPT {
1626 return __s.type() == file_type::directory;
1627}
1628
1629inline _LIBCPP_INLINE_VISIBILITY
1630bool is_directory(const path& __p) {
1631 return is_directory(__status(__p));
1632}
1633
1634inline _LIBCPP_INLINE_VISIBILITY
1635bool is_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1636 return is_directory(__status(__p, &__ec));
1637}
1638
1639inline _LIBCPP_INLINE_VISIBILITY
1640bool is_empty(const path& __p) {
1641 return __fs_is_empty(__p);
1642}
1643
1644inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001645bool is_empty(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001646 return __fs_is_empty(__p, &__ec);
1647}
1648
1649inline _LIBCPP_INLINE_VISIBILITY
1650bool is_fifo(file_status __s) _NOEXCEPT {
1651 return __s.type() == file_type::fifo;
1652}
1653inline _LIBCPP_INLINE_VISIBILITY
1654bool is_fifo(const path& __p) {
1655 return is_fifo(__status(__p));
1656}
1657
1658inline _LIBCPP_INLINE_VISIBILITY
1659bool is_fifo(const path& __p, error_code& __ec) _NOEXCEPT {
1660 return is_fifo(__status(__p, &__ec));
1661}
1662
1663inline _LIBCPP_INLINE_VISIBILITY
1664bool is_regular_file(file_status __s) _NOEXCEPT {
1665 return __s.type() == file_type::regular;
1666}
1667
1668inline _LIBCPP_INLINE_VISIBILITY
1669bool is_regular_file(const path& __p) {
1670 return is_regular_file(__status(__p));
1671}
1672
1673inline _LIBCPP_INLINE_VISIBILITY
1674bool is_regular_file(const path& __p, error_code& __ec) _NOEXCEPT {
1675 return is_regular_file(__status(__p, &__ec));
1676}
1677
1678inline _LIBCPP_INLINE_VISIBILITY
1679bool is_socket(file_status __s) _NOEXCEPT {
1680 return __s.type() == file_type::socket;
1681}
1682
1683inline _LIBCPP_INLINE_VISIBILITY
1684bool is_socket(const path& __p) {
1685 return is_socket(__status(__p));
1686}
1687
1688inline _LIBCPP_INLINE_VISIBILITY
1689bool is_socket(const path& __p, error_code& __ec) _NOEXCEPT {
1690 return is_socket(__status(__p, &__ec));
1691}
1692
1693inline _LIBCPP_INLINE_VISIBILITY
1694bool is_symlink(file_status __s) _NOEXCEPT {
1695 return __s.type() == file_type::symlink;
1696}
1697
1698inline _LIBCPP_INLINE_VISIBILITY
1699bool is_symlink(const path& __p) {
1700 return is_symlink(__symlink_status(__p));
1701}
1702
1703inline _LIBCPP_INLINE_VISIBILITY
1704bool is_symlink(const path& __p, error_code& __ec) _NOEXCEPT {
1705 return is_symlink(__symlink_status(__p, &__ec));
1706}
1707
1708inline _LIBCPP_INLINE_VISIBILITY
1709bool is_other(file_status __s) _NOEXCEPT {
1710 return exists(__s)
1711 && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s);
1712}
1713
1714inline _LIBCPP_INLINE_VISIBILITY
1715bool is_other(const path& __p) {
1716 return is_other(__status(__p));
1717}
1718
1719inline _LIBCPP_INLINE_VISIBILITY
1720bool is_other(const path& __p, error_code& __ec) _NOEXCEPT {
1721 return is_other(__status(__p, &__ec));
1722}
1723
1724inline _LIBCPP_INLINE_VISIBILITY
1725file_time_type last_write_time(const path& __p) {
1726 return __last_write_time(__p);
1727}
1728
1729inline _LIBCPP_INLINE_VISIBILITY
1730file_time_type last_write_time(const path& __p, error_code& __ec) _NOEXCEPT {
1731 return __last_write_time(__p, &__ec);
1732}
1733
1734inline _LIBCPP_INLINE_VISIBILITY
1735void last_write_time(const path& __p, file_time_type __t) {
1736 __last_write_time(__p, __t);
1737}
1738
1739inline _LIBCPP_INLINE_VISIBILITY
1740void last_write_time(const path& __p, file_time_type __t, error_code& __ec) _NOEXCEPT {
1741 __last_write_time(__p, __t, &__ec);
1742}
1743
1744inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf2c93732018-03-26 06:23:55 +00001745void permissions(const path& __p, perms __prms,
1746 perm_options __opts = perm_options::replace) {
1747 __permissions(__p, __prms, __opts);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001748}
1749
1750inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf2c93732018-03-26 06:23:55 +00001751void permissions(const path& __p, perms __prms, error_code& __ec) _NOEXCEPT {
1752 __permissions(__p, __prms, perm_options::replace, &__ec);
1753}
1754
1755inline _LIBCPP_INLINE_VISIBILITY
1756void permissions(const path& __p, perms __prms, perm_options __opts,
1757 error_code& __ec) {
1758 __permissions(__p, __prms, __opts, &__ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001759}
1760
1761inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1e34c762018-04-02 23:03:41 +00001762path proximate(const path& __p, const path& __base, error_code& __ec) {
1763 path __tmp = __weakly_canonical(__p, &__ec);
1764 if (__ec)
1765 return {};
1766 path __tmp_base = __weakly_canonical(__base, &__ec);
1767 if (__ec)
1768 return {};
1769 return __tmp.lexically_proximate(__tmp_base);
1770}
1771
1772inline _LIBCPP_INLINE_VISIBILITY
1773path proximate(const path& __p, error_code& __ec) {
1774 return proximate(__p, current_path(), __ec);
1775}
1776
1777inline _LIBCPP_INLINE_VISIBILITY
1778path proximate(const path& __p, const path& __base = current_path()) {
1779 return __weakly_canonical(__p).lexically_proximate(__weakly_canonical(__base));
1780}
1781
1782inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001783path read_symlink(const path& __p) {
1784 return __read_symlink(__p);
1785}
1786
1787inline _LIBCPP_INLINE_VISIBILITY
1788path read_symlink(const path& __p, error_code& __ec) {
1789 return __read_symlink(__p, &__ec);
1790}
1791
Eric Fiselier1e34c762018-04-02 23:03:41 +00001792
1793inline _LIBCPP_INLINE_VISIBILITY
1794path relative(const path& __p, const path& __base, error_code& __ec) {
1795 path __tmp = __weakly_canonical(__p, &__ec);
1796 if (__ec)
1797 return path();
1798 path __tmpbase = __weakly_canonical(__base, &__ec);
1799 if (__ec)
1800 return path();
1801 return __tmp.lexically_relative(__tmpbase);
1802}
1803
1804inline _LIBCPP_INLINE_VISIBILITY
1805path relative(const path& __p, error_code& __ec) {
1806 return relative(__p, current_path(), __ec);
1807}
1808
1809inline _LIBCPP_INLINE_VISIBILITY
1810path relative(const path& __p, const path& __base=current_path()) {
1811 return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
1812}
1813
1814
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001815inline _LIBCPP_INLINE_VISIBILITY
1816bool remove(const path& __p) {
1817 return __remove(__p);
1818}
1819
1820inline _LIBCPP_INLINE_VISIBILITY
1821bool remove(const path& __p, error_code& __ec) _NOEXCEPT {
1822 return __remove(__p, &__ec);
1823}
1824
1825inline _LIBCPP_INLINE_VISIBILITY
1826uintmax_t remove_all(const path& __p) {
1827 return __remove_all(__p);
1828}
1829
1830inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001831uintmax_t remove_all(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001832 return __remove_all(__p, &__ec);
1833}
1834
1835inline _LIBCPP_INLINE_VISIBILITY
1836void rename(const path& __from, const path& __to) {
1837 return __rename(__from, __to);
1838}
1839
1840inline _LIBCPP_INLINE_VISIBILITY
1841void rename(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
1842 return __rename(__from, __to, &__ec);
1843}
1844
1845inline _LIBCPP_INLINE_VISIBILITY
1846void resize_file(const path& __p, uintmax_t __ns) {
1847 return __resize_file(__p, __ns);
1848}
1849
1850inline _LIBCPP_INLINE_VISIBILITY
1851void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) _NOEXCEPT {
1852 return __resize_file(__p, __ns, &__ec);
1853}
1854
1855inline _LIBCPP_INLINE_VISIBILITY
1856space_info space(const path& __p) {
1857 return __space(__p);
1858}
1859
1860inline _LIBCPP_INLINE_VISIBILITY
1861space_info space(const path& __p, error_code& __ec) _NOEXCEPT {
1862 return __space(__p, &__ec);
1863}
1864
1865inline _LIBCPP_INLINE_VISIBILITY
1866file_status status(const path& __p) {
1867 return __status(__p);
1868}
1869
1870inline _LIBCPP_INLINE_VISIBILITY
1871file_status status(const path& __p, error_code& __ec) _NOEXCEPT {
1872 return __status(__p, &__ec);
1873}
1874
1875inline _LIBCPP_INLINE_VISIBILITY
1876file_status symlink_status(const path& __p) {
1877 return __symlink_status(__p);
1878}
1879
1880inline _LIBCPP_INLINE_VISIBILITY
1881file_status symlink_status(const path& __p, error_code& __ec) _NOEXCEPT {
1882 return __symlink_status(__p, &__ec);
1883}
1884
1885inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001886path temp_directory_path() {
1887 return __temp_directory_path();
1888}
1889
1890inline _LIBCPP_INLINE_VISIBILITY
1891path temp_directory_path(error_code& __ec) {
1892 return __temp_directory_path(&__ec);
1893}
1894
Eric Fiselier1e34c762018-04-02 23:03:41 +00001895inline _LIBCPP_INLINE_VISIBILITY
1896path weakly_canonical(path const& __p) {
1897 return __weakly_canonical(__p);
1898}
1899
1900inline _LIBCPP_INLINE_VISIBILITY
1901path weakly_canonical(path const& __p, error_code& __ec) {
1902 return __weakly_canonical(__p, &__ec);
1903}
1904
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001905
1906class directory_entry
1907{
1908 typedef _VSTD_FS::path _Path;
1909
1910public:
1911 // constructors and destructors
1912 directory_entry() _NOEXCEPT = default;
1913 directory_entry(directory_entry const&) = default;
1914 directory_entry(directory_entry&&) _NOEXCEPT = default;
1915
1916 _LIBCPP_INLINE_VISIBILITY
1917 explicit directory_entry(_Path const& __p) : __p_(__p) {}
1918
1919 ~directory_entry() {}
1920
1921 directory_entry& operator=(directory_entry const&) = default;
1922 directory_entry& operator=(directory_entry&&) _NOEXCEPT = default;
1923
1924 _LIBCPP_INLINE_VISIBILITY
1925 void assign(_Path const& __p) {
1926 __p_ = __p;
1927 }
1928
1929 _LIBCPP_INLINE_VISIBILITY
1930 void replace_filename(_Path const& __p) {
1931 __p_ = __p_.parent_path() / __p;
1932 }
1933
1934 _LIBCPP_INLINE_VISIBILITY
1935 _Path const& path() const _NOEXCEPT {
1936 return __p_;
1937 }
1938
1939 _LIBCPP_INLINE_VISIBILITY
1940 operator const _Path&() const _NOEXCEPT {
1941 return __p_;
1942 }
1943
1944 _LIBCPP_INLINE_VISIBILITY
1945 file_status status() const {
1946 return _VSTD_FS::status(__p_);
1947 }
1948
1949 _LIBCPP_INLINE_VISIBILITY
1950 file_status status(error_code& __ec) const _NOEXCEPT {
1951 return _VSTD_FS::status(__p_, __ec);
1952 }
1953
1954 _LIBCPP_INLINE_VISIBILITY
1955 file_status symlink_status() const {
1956 return _VSTD_FS::symlink_status(__p_);
1957 }
1958
1959 _LIBCPP_INLINE_VISIBILITY
1960 file_status symlink_status(error_code& __ec) const _NOEXCEPT {
1961 return _VSTD_FS::symlink_status(__p_, __ec);
1962 }
1963
1964 _LIBCPP_INLINE_VISIBILITY
1965 bool operator< (directory_entry const& __rhs) const _NOEXCEPT {
1966 return __p_ < __rhs.__p_;
1967 }
1968
1969 _LIBCPP_INLINE_VISIBILITY
1970 bool operator==(directory_entry const& __rhs) const _NOEXCEPT {
1971 return __p_ == __rhs.__p_;
1972 }
1973
1974 _LIBCPP_INLINE_VISIBILITY
1975 bool operator!=(directory_entry const& __rhs) const _NOEXCEPT {
1976 return __p_ != __rhs.__p_;
1977 }
1978
1979 _LIBCPP_INLINE_VISIBILITY
1980 bool operator<=(directory_entry const& __rhs) const _NOEXCEPT {
1981 return __p_ <= __rhs.__p_;
1982 }
1983
1984 _LIBCPP_INLINE_VISIBILITY
1985 bool operator> (directory_entry const& __rhs) const _NOEXCEPT {
1986 return __p_ > __rhs.__p_;
1987 }
1988
1989 _LIBCPP_INLINE_VISIBILITY
1990 bool operator>=(directory_entry const& __rhs) const _NOEXCEPT {
1991 return __p_ >= __rhs.__p_;
1992 }
1993private:
1994 _Path __p_;
1995};
1996
1997
1998class directory_iterator;
1999class recursive_directory_iterator;
2000class __dir_stream;
2001
2002class __dir_element_proxy {
2003public:
2004
2005 inline _LIBCPP_INLINE_VISIBILITY
2006 directory_entry operator*() { return _VSTD::move(__elem_); }
2007
2008private:
2009 friend class directory_iterator;
2010 friend class recursive_directory_iterator;
2011 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
2012 __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {}
2013 directory_entry __elem_;
2014};
2015
2016class directory_iterator
2017{
2018public:
2019 typedef directory_entry value_type;
2020 typedef ptrdiff_t difference_type;
2021 typedef value_type const* pointer;
2022 typedef value_type const& reference;
2023 typedef input_iterator_tag iterator_category;
2024
2025public:
2026 //ctor & dtor
2027 directory_iterator() _NOEXCEPT
2028 { }
2029
2030 explicit directory_iterator(const path& __p)
2031 : directory_iterator(__p, nullptr)
2032 { }
2033
2034 directory_iterator(const path& __p, directory_options __opts)
2035 : directory_iterator(__p, nullptr, __opts)
2036 { }
2037
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002038 directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002039 : directory_iterator(__p, &__ec)
2040 { }
2041
2042 directory_iterator(const path& __p, directory_options __opts,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002043 error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002044 : directory_iterator(__p, &__ec, __opts)
2045 { }
2046
2047 directory_iterator(const directory_iterator&) = default;
2048 directory_iterator(directory_iterator&&) = default;
2049 directory_iterator& operator=(const directory_iterator&) = default;
2050
2051 directory_iterator& operator=(directory_iterator&& __o) _NOEXCEPT {
2052 // non-default implementation provided to support self-move assign.
2053 if (this != &__o) {
2054 __imp_ = _VSTD::move(__o.__imp_);
2055 }
2056 return *this;
2057 }
2058
2059 ~directory_iterator() = default;
2060
2061 const directory_entry& operator*() const {
2062 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002063 return __dereference();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002064 }
2065
2066 const directory_entry* operator->() const
2067 { return &**this; }
2068
2069 directory_iterator& operator++()
2070 { return __increment(); }
2071
2072 __dir_element_proxy operator++(int) {
2073 __dir_element_proxy __p(**this);
2074 __increment();
2075 return __p;
2076 }
2077
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002078 directory_iterator& increment(error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002079 { return __increment(&__ec); }
2080
2081private:
Eric Fiselier03f7d102016-09-16 00:07:16 +00002082 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002083 friend bool operator==(const directory_iterator& __lhs,
2084 const directory_iterator& __rhs) _NOEXCEPT;
2085
2086 // construct the dir_stream
2087 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002088 directory_iterator(const path&, error_code *,
2089 directory_options = directory_options::none);
2090
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002091 _LIBCPP_FUNC_VIS
2092 directory_iterator& __increment(error_code * __ec = nullptr);
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002093
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002094 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002095 const directory_entry& __dereference() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002096
2097private:
2098 shared_ptr<__dir_stream> __imp_;
2099};
2100
2101
2102inline _LIBCPP_INLINE_VISIBILITY
2103bool operator==(const directory_iterator& __lhs,
2104 const directory_iterator& __rhs) _NOEXCEPT {
2105 return __lhs.__imp_ == __rhs.__imp_;
2106}
2107
2108inline _LIBCPP_INLINE_VISIBILITY
2109bool operator!=(const directory_iterator& __lhs,
2110 const directory_iterator& __rhs) _NOEXCEPT {
2111 return !(__lhs == __rhs);
2112}
2113
2114// enable directory_iterator range-based for statements
2115inline _LIBCPP_INLINE_VISIBILITY
2116directory_iterator begin(directory_iterator __iter) _NOEXCEPT {
2117 return __iter;
2118}
2119
2120inline _LIBCPP_INLINE_VISIBILITY
2121directory_iterator end(const directory_iterator&) _NOEXCEPT {
2122 return directory_iterator();
2123}
2124
2125class recursive_directory_iterator {
2126public:
2127 using value_type = directory_entry;
2128 using difference_type = std::ptrdiff_t;
2129 using pointer = directory_entry const *;
2130 using reference = directory_entry const &;
2131 using iterator_category = std::input_iterator_tag;
2132
2133public:
2134 // constructors and destructor
2135 _LIBCPP_INLINE_VISIBILITY
2136 recursive_directory_iterator() _NOEXCEPT
2137 : __rec_(false)
2138 {}
2139
2140 _LIBCPP_INLINE_VISIBILITY
2141 explicit recursive_directory_iterator(const path& __p,
2142 directory_options __xoptions = directory_options::none)
2143 : recursive_directory_iterator(__p, __xoptions, nullptr)
2144 { }
2145
2146 _LIBCPP_INLINE_VISIBILITY
2147 recursive_directory_iterator(const path& __p,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002148 directory_options __xoptions, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002149 : recursive_directory_iterator(__p, __xoptions, &__ec)
2150 { }
2151
2152 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002153 recursive_directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002154 : recursive_directory_iterator(__p, directory_options::none, &__ec)
2155 { }
2156
2157 recursive_directory_iterator(const recursive_directory_iterator&) = default;
2158 recursive_directory_iterator(recursive_directory_iterator&&) = default;
2159
2160 recursive_directory_iterator &
2161 operator=(const recursive_directory_iterator&) = default;
2162
2163 _LIBCPP_INLINE_VISIBILITY
2164 recursive_directory_iterator &
2165 operator=(recursive_directory_iterator&& __o) noexcept {
2166 // non-default implementation provided to support self-move assign.
2167 if (this != &__o) {
2168 __imp_ = _VSTD::move(__o.__imp_);
2169 __rec_ = __o.__rec_;
2170 }
2171 return *this;
2172 }
2173
2174 ~recursive_directory_iterator() = default;
2175
2176 _LIBCPP_INLINE_VISIBILITY
2177 const directory_entry& operator*() const
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002178 { return __dereference(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002179
2180 _LIBCPP_INLINE_VISIBILITY
2181 const directory_entry* operator->() const
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002182 { return &__dereference(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002183
2184 recursive_directory_iterator& operator++()
2185 { return __increment(); }
2186
2187 _LIBCPP_INLINE_VISIBILITY
2188 __dir_element_proxy operator++(int) {
2189 __dir_element_proxy __p(**this);
2190 __increment();
2191 return __p;
2192 }
2193
2194 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002195 recursive_directory_iterator& increment(error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002196 { return __increment(&__ec); }
2197
2198 _LIBCPP_FUNC_VIS directory_options options() const;
2199 _LIBCPP_FUNC_VIS int depth() const;
2200
2201 _LIBCPP_INLINE_VISIBILITY
2202 void pop() { __pop(); }
2203
2204 _LIBCPP_INLINE_VISIBILITY
2205 void pop(error_code& __ec)
2206 { __pop(&__ec); }
2207
2208 _LIBCPP_INLINE_VISIBILITY
2209 bool recursion_pending() const
2210 { return __rec_; }
2211
2212 _LIBCPP_INLINE_VISIBILITY
2213 void disable_recursion_pending()
2214 { __rec_ = false; }
2215
2216private:
2217 recursive_directory_iterator(const path& __p, directory_options __opt,
2218 error_code *__ec);
2219
2220 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002221 const directory_entry& __dereference() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002222
2223 _LIBCPP_FUNC_VIS
2224 bool __try_recursion(error_code* __ec);
2225
2226 _LIBCPP_FUNC_VIS
2227 void __advance(error_code* __ec=nullptr);
2228
2229 _LIBCPP_FUNC_VIS
2230 recursive_directory_iterator& __increment(error_code *__ec=nullptr);
2231
2232 _LIBCPP_FUNC_VIS
2233 void __pop(error_code* __ec=nullptr);
2234
Eric Fiselier03f7d102016-09-16 00:07:16 +00002235 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002236 friend bool operator==(const recursive_directory_iterator&,
2237 const recursive_directory_iterator&) _NOEXCEPT;
2238
2239 struct __shared_imp;
2240 shared_ptr<__shared_imp> __imp_;
2241 bool __rec_;
2242}; // class recursive_directory_iterator
2243
2244
Eric Fiselier03f7d102016-09-16 00:07:16 +00002245inline _LIBCPP_INLINE_VISIBILITY
2246bool operator==(const recursive_directory_iterator& __lhs,
2247 const recursive_directory_iterator& __rhs) _NOEXCEPT
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002248{
2249 return __lhs.__imp_ == __rhs.__imp_;
2250}
2251
2252_LIBCPP_INLINE_VISIBILITY
2253inline bool operator!=(const recursive_directory_iterator& __lhs,
2254 const recursive_directory_iterator& __rhs) _NOEXCEPT
2255{
2256 return !(__lhs == __rhs);
2257}
2258// enable recursive_directory_iterator range-based for statements
2259inline _LIBCPP_INLINE_VISIBILITY
2260recursive_directory_iterator begin(recursive_directory_iterator __iter) _NOEXCEPT {
2261 return __iter;
2262}
2263
2264inline _LIBCPP_INLINE_VISIBILITY
2265recursive_directory_iterator end(const recursive_directory_iterator&) _NOEXCEPT {
2266 return recursive_directory_iterator();
2267}
2268
2269_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
2270
2271#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM