blob: a8518249dd8956596bb633b36756c7c3573f1c11 [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
473 _LIBCPP_ALWAYS_INLINE
474 file_type type() const _NOEXCEPT {
475 return __ft_;
476 }
477
478 _LIBCPP_ALWAYS_INLINE
479 perms permissions() const _NOEXCEPT {
480 return __prms_;
481 }
482
483 // modifiers
484 _LIBCPP_ALWAYS_INLINE
485 void type(file_type __ft) _NOEXCEPT {
486 __ft_ = __ft;
487 }
488
489 _LIBCPP_ALWAYS_INLINE
490 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
1109inline _LIBCPP_ALWAYS_INLINE
1110void 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) {
1143 return path(__lhs) /= __rhs;
1144}
1145
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001146template <class _Source>
1147_LIBCPP_INLINE_VISIBILITY
1148typename enable_if<__is_pathable<_Source>::value, path>::type
1149u8path(const _Source& __s){
1150 static_assert(is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1151 "u8path(Source const&) requires Source have a character type of type 'char'");
1152 return path(__s);
1153}
1154
1155template <class _InputIt>
1156_LIBCPP_INLINE_VISIBILITY
1157typename enable_if<__is_pathable<_InputIt>::value, path>::type
1158u8path(_InputIt __f, _InputIt __l) {
1159 static_assert(is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1160 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1161 return path(__f, __l);
1162}
1163
1164class _LIBCPP_TYPE_VIS path::iterator
1165{
1166public:
1167 typedef bidirectional_iterator_tag iterator_category;
Eric Fiselier08673732017-04-04 01:05:59 +00001168
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001169 typedef path value_type;
1170 typedef std::ptrdiff_t difference_type;
1171 typedef const path* pointer;
1172 typedef const path& reference;
Eric Fiselier706e2c72017-04-13 02:54:13 +00001173
1174 typedef void __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001175public:
1176 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier271a19e2016-10-30 23:30:38 +00001177 iterator() : __stashed_elem_(), __path_ptr_(nullptr),
1178 __entry_(), __state_(__singular) {}
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001179
1180 iterator(const iterator&) = default;
1181 ~iterator() = default;
1182
1183 iterator& operator=(const iterator&) = default;
1184
1185 _LIBCPP_INLINE_VISIBILITY
1186 reference operator*() const {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001187 return __stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001188 }
1189
1190 _LIBCPP_INLINE_VISIBILITY
1191 pointer operator->() const {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001192 return &__stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001193 }
1194
1195 _LIBCPP_INLINE_VISIBILITY
1196 iterator& operator++() {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001197 _LIBCPP_ASSERT(__state_ != __singular,
1198 "attempting to increment a singular iterator");
1199 _LIBCPP_ASSERT(__state_ != __at_end,
1200 "attempting to increment the end iterator");
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001201 return __increment();
1202 }
1203
1204 _LIBCPP_INLINE_VISIBILITY
1205 iterator operator++(int) {
1206 iterator __it(*this);
1207 this->operator++();
1208 return __it;
1209 }
1210
1211 _LIBCPP_INLINE_VISIBILITY
1212 iterator& operator--() {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001213 _LIBCPP_ASSERT(__state_ != __singular,
1214 "attempting to decrement a singular iterator");
1215 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
1216 "attempting to decrement the begin iterator");
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001217 return __decrement();
1218 }
1219
1220 _LIBCPP_INLINE_VISIBILITY
1221 iterator operator--(int) {
1222 iterator __it(*this);
1223 this->operator--();
1224 return __it;
1225 }
1226
1227private:
1228 friend class path;
Eric Fiselier03f7d102016-09-16 00:07:16 +00001229
Eric Fiselier271a19e2016-10-30 23:30:38 +00001230 static constexpr unsigned char __singular = 0;
1231 static constexpr unsigned char __at_end = 6;
1232
Eric Fiselier03f7d102016-09-16 00:07:16 +00001233 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001234 friend bool operator==(const iterator&, const iterator&);
1235
Saleem Abdulrasool52241cb2017-01-30 03:58:26 +00001236 iterator& __increment();
1237 iterator& __decrement();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001238
Eric Fiselier271a19e2016-10-30 23:30:38 +00001239 path __stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001240 const path* __path_ptr_;
Eric Fiselier271a19e2016-10-30 23:30:38 +00001241 path::__string_view __entry_;
1242 unsigned char __state_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001243};
1244
1245inline _LIBCPP_INLINE_VISIBILITY
1246bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) {
1247 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
Eric Fiselier271a19e2016-10-30 23:30:38 +00001248 __lhs.__entry_.data() == __rhs.__entry_.data();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001249}
1250
1251inline _LIBCPP_INLINE_VISIBILITY
1252bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) {
1253 return !(__lhs == __rhs);
1254}
1255
1256class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error
1257{
1258public:
1259 _LIBCPP_INLINE_VISIBILITY
1260 filesystem_error(const string& __what, error_code __ec)
1261 : system_error(__ec, __what),
1262 __paths_(make_shared<_Storage>(path(), path()))
1263 {}
1264
1265 _LIBCPP_INLINE_VISIBILITY
1266 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1267 : system_error(__ec, __what),
1268 __paths_(make_shared<_Storage>(__p1, path()))
1269 {}
1270
1271 _LIBCPP_INLINE_VISIBILITY
1272 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1273 error_code __ec)
1274 : system_error(__ec, __what),
1275 __paths_(make_shared<_Storage>(__p1, __p2))
1276 {}
1277
1278 _LIBCPP_INLINE_VISIBILITY
1279 const path& path1() const _NOEXCEPT {
1280 return __paths_->first;
1281 }
1282
1283 _LIBCPP_INLINE_VISIBILITY
1284 const path& path2() const _NOEXCEPT {
1285 return __paths_->second;
1286 }
1287
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001288 ~filesystem_error() override; // key function
1289
1290 // TODO(ericwf): Create a custom error message.
1291 //const char* what() const _NOEXCEPT;
1292
1293private:
1294 typedef pair<path, path> _Storage;
1295 shared_ptr<_Storage> __paths_;
1296};
1297
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001298template <class... _Args>
1299_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00001300#ifndef _LIBCPP_NO_EXCEPTIONS
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001301void __throw_filesystem_error(_Args && ...__args)
1302{
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001303 throw filesystem_error(std::forward<_Args>(__args)...);
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001304}
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00001305#else
1306void __throw_filesystem_error(_Args&&...)
1307{
1308 _VSTD::abort();
1309}
1310#endif
1311
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001312
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001313// operational functions
1314
1315_LIBCPP_FUNC_VIS
Eric Fiselier1e34c762018-04-02 23:03:41 +00001316path __absolute(const path&, error_code *__ec=nullptr);
1317_LIBCPP_FUNC_VIS
1318path __canonical(const path&, error_code *__ec=nullptr);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001319_LIBCPP_FUNC_VIS
1320void __copy(const path& __from, const path& __to, copy_options __opt,
1321 error_code *__ec=nullptr);
1322_LIBCPP_FUNC_VIS
1323bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1324 error_code *__ec=nullptr);
1325_LIBCPP_FUNC_VIS
1326void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1327 error_code *__ec=nullptr);
1328_LIBCPP_FUNC_VIS
1329bool __create_directories(const path& p, error_code *ec=nullptr);
1330_LIBCPP_FUNC_VIS
1331bool __create_directory(const path& p, error_code *ec=nullptr);
1332_LIBCPP_FUNC_VIS
1333bool __create_directory(const path& p, const path & attributes,
1334 error_code *ec=nullptr);
1335_LIBCPP_FUNC_VIS
1336void __create_directory_symlink(const path& __to, const path& __new_symlink,
1337 error_code *__ec=nullptr);
1338_LIBCPP_FUNC_VIS
1339void __create_hard_link(const path& __to, const path& __new_hard_link,
1340 error_code *__ec=nullptr);
1341_LIBCPP_FUNC_VIS
1342void __create_symlink(const path& __to, const path& __new_symlink,
1343 error_code *__ec=nullptr);
1344_LIBCPP_FUNC_VIS
1345path __current_path(error_code *__ec=nullptr);
1346_LIBCPP_FUNC_VIS
1347void __current_path(const path&, error_code *__ec=nullptr);
1348_LIBCPP_FUNC_VIS
1349bool __equivalent(const path&, const path&, error_code *__ec=nullptr);
1350_LIBCPP_FUNC_VIS
1351uintmax_t __file_size(const path&, error_code *__ec=nullptr);
1352_LIBCPP_FUNC_VIS
1353uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr);
1354_LIBCPP_FUNC_VIS
1355bool __fs_is_empty(const path& p, error_code *ec=nullptr);
1356_LIBCPP_FUNC_VIS
1357file_time_type __last_write_time(const path& p, error_code *ec=nullptr);
1358_LIBCPP_FUNC_VIS
1359void __last_write_time(const path& p, file_time_type new_time,
1360 error_code *ec=nullptr);
1361_LIBCPP_FUNC_VIS
Eric Fiselierf2c93732018-03-26 06:23:55 +00001362void __permissions(const path&, perms, perm_options, error_code* = nullptr);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001363_LIBCPP_FUNC_VIS
1364path __read_symlink(const path& p, error_code *ec=nullptr);
1365_LIBCPP_FUNC_VIS
1366bool __remove(const path& p, error_code *ec=nullptr);
1367_LIBCPP_FUNC_VIS
1368uintmax_t __remove_all(const path& p, error_code *ec=nullptr);
1369_LIBCPP_FUNC_VIS
1370void __rename(const path& from, const path& to, error_code *ec=nullptr);
1371_LIBCPP_FUNC_VIS
1372void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr);
1373_LIBCPP_FUNC_VIS
1374space_info __space(const path&, error_code *__ec=nullptr);
1375_LIBCPP_FUNC_VIS
1376file_status __status(const path&, error_code *__ec=nullptr);
1377_LIBCPP_FUNC_VIS
1378file_status __symlink_status(const path&, error_code *__ec=nullptr);
1379_LIBCPP_FUNC_VIS
1380path __system_complete(const path&, error_code *__ec=nullptr);
1381_LIBCPP_FUNC_VIS
1382path __temp_directory_path(error_code *__ec=nullptr);
Eric Fiselier1e34c762018-04-02 23:03:41 +00001383_LIBCPP_FUNC_VIS
1384path __weakly_canonical(path const& __p, error_code *__ec=nullptr);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001385
1386inline _LIBCPP_INLINE_VISIBILITY
1387path current_path() {
1388 return __current_path();
1389}
1390
1391inline _LIBCPP_INLINE_VISIBILITY
1392path current_path(error_code& __ec) {
1393 return __current_path(&__ec);
1394}
1395
1396inline _LIBCPP_INLINE_VISIBILITY
1397void current_path(const path& __p) {
1398 __current_path(__p);
1399}
1400
1401inline _LIBCPP_INLINE_VISIBILITY
1402void current_path(const path& __p, error_code& __ec) _NOEXCEPT {
1403 __current_path(__p, &__ec);
1404}
1405
Eric Fiselier1e34c762018-04-02 23:03:41 +00001406inline _LIBCPP_INLINE_VISIBILITY
1407path absolute(const path& __p) {
1408 return __absolute(__p);
1409}
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001410
1411inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1e34c762018-04-02 23:03:41 +00001412path absolute(const path& __p, error_code &__ec) {
1413 return __absolute(__p, &__ec);
1414}
1415
1416inline _LIBCPP_INLINE_VISIBILITY
1417path canonical(const path& __p) {
1418 return __canonical(__p);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001419}
1420
1421inline _LIBCPP_INLINE_VISIBILITY
1422path canonical(const path& __p, error_code& __ec) {
Eric Fiselier1e34c762018-04-02 23:03:41 +00001423 return __canonical(__p, &__ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001424}
1425
1426inline _LIBCPP_INLINE_VISIBILITY
1427void copy(const path& __from, const path& __to) {
1428 __copy(__from, __to, copy_options::none);
1429}
1430
1431inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001432void copy(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001433 __copy(__from, __to, copy_options::none, &__ec);
1434}
1435
1436inline _LIBCPP_INLINE_VISIBILITY
1437void copy(const path& __from, const path& __to, copy_options __opt) {
1438 __copy(__from, __to, __opt);
1439}
1440
1441inline _LIBCPP_INLINE_VISIBILITY
1442void copy(const path& __from, const path& __to,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001443 copy_options __opt, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001444 __copy(__from, __to, __opt, &__ec);
1445}
1446
1447inline _LIBCPP_INLINE_VISIBILITY
1448bool copy_file(const path& __from, const path& __to) {
1449 return __copy_file(__from, __to, copy_options::none);
1450}
1451
1452inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001453bool copy_file(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001454 return __copy_file(__from, __to, copy_options::none, &__ec);
1455}
1456
1457inline _LIBCPP_INLINE_VISIBILITY
1458bool copy_file(const path& __from, const path& __to, copy_options __opt) {
1459 return __copy_file(__from, __to, __opt);
1460}
1461
1462inline _LIBCPP_INLINE_VISIBILITY
1463bool copy_file(const path& __from, const path& __to,
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001464 copy_options __opt, error_code& __ec){
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001465 return __copy_file(__from, __to, __opt, &__ec);
1466}
1467
1468inline _LIBCPP_INLINE_VISIBILITY
1469void copy_symlink(const path& __existing, const path& __new) {
1470 __copy_symlink(__existing, __new);
1471}
1472
1473inline _LIBCPP_INLINE_VISIBILITY
1474void copy_symlink(const path& __ext, const path& __new, error_code& __ec) _NOEXCEPT {
1475 __copy_symlink(__ext, __new, &__ec);
1476}
1477
1478inline _LIBCPP_INLINE_VISIBILITY
1479bool create_directories(const path& __p) {
1480 return __create_directories(__p);
1481}
1482
1483inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001484bool create_directories(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001485 return __create_directories(__p, &__ec);
1486}
1487
1488inline _LIBCPP_INLINE_VISIBILITY
1489bool create_directory(const path& __p) {
1490 return __create_directory(__p);
1491}
1492
1493inline _LIBCPP_INLINE_VISIBILITY
1494bool create_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1495 return __create_directory(__p, &__ec);
1496}
1497
1498inline _LIBCPP_INLINE_VISIBILITY
1499bool create_directory(const path& __p, const path& __attrs) {
1500 return __create_directory(__p, __attrs);
1501}
1502
1503inline _LIBCPP_INLINE_VISIBILITY
1504bool create_directory(const path& __p, const path& __attrs, error_code& __ec) _NOEXCEPT {
1505 return __create_directory(__p, __attrs, &__ec);
1506}
1507
1508inline _LIBCPP_INLINE_VISIBILITY
1509void create_directory_symlink(const path& __to, const path& __new) {
1510 __create_directory_symlink(__to, __new);
1511}
1512
1513inline _LIBCPP_INLINE_VISIBILITY
1514void create_directory_symlink(const path& __to, const path& __new,
1515 error_code& __ec) _NOEXCEPT {
1516 __create_directory_symlink(__to, __new, &__ec);
1517}
1518
1519inline _LIBCPP_INLINE_VISIBILITY
1520void create_hard_link(const path& __to, const path& __new) {
1521 __create_hard_link(__to, __new);
1522}
1523
1524inline _LIBCPP_INLINE_VISIBILITY
1525void create_hard_link(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
1526 __create_hard_link(__to, __new, &__ec);
1527}
1528
1529inline _LIBCPP_INLINE_VISIBILITY
1530void create_symlink(const path& __to, const path& __new) {
1531 __create_symlink(__to, __new);
1532}
1533
1534inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1e34c762018-04-02 23:03:41 +00001535void create_symlink(const path& __to, const path& __new,
1536 error_code& __ec) _NOEXCEPT {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001537 return __create_symlink(__to, __new, &__ec);
1538}
1539
1540inline _LIBCPP_INLINE_VISIBILITY
1541bool status_known(file_status __s) _NOEXCEPT {
1542 return __s.type() != file_type::none;
1543}
1544
1545inline _LIBCPP_INLINE_VISIBILITY
1546bool exists(file_status __s) _NOEXCEPT {
1547 return status_known(__s) && __s.type() != file_type::not_found;
1548}
1549
1550inline _LIBCPP_INLINE_VISIBILITY
1551bool exists(const path& __p) {
1552 return exists(__status(__p));
1553}
1554
1555inline _LIBCPP_INLINE_VISIBILITY
1556bool exists(const path& __p, error_code& __ec) _NOEXCEPT {
Eric Fiselier756a6bd2016-06-21 22:11:16 +00001557 auto __s = __status(__p, &__ec);
1558 if (status_known(__s)) __ec.clear();
1559 return exists(__s);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001560}
1561
1562inline _LIBCPP_INLINE_VISIBILITY
1563bool equivalent(const path& __p1, const path& __p2) {
1564 return __equivalent(__p1, __p2);
1565}
1566
1567inline _LIBCPP_INLINE_VISIBILITY
1568bool equivalent(const path& __p1, const path& __p2, error_code& __ec) _NOEXCEPT {
1569 return __equivalent(__p1, __p2, &__ec);
1570}
1571
1572inline _LIBCPP_INLINE_VISIBILITY
1573uintmax_t file_size(const path& __p) {
1574 return __file_size(__p);
1575}
1576
1577inline _LIBCPP_INLINE_VISIBILITY
1578uintmax_t file_size(const path& __p, error_code& __ec) _NOEXCEPT {
1579 return __file_size(__p, &__ec);
1580}
1581
1582inline _LIBCPP_INLINE_VISIBILITY
1583uintmax_t hard_link_count(const path& __p) {
1584 return __hard_link_count(__p);
1585}
1586
1587inline _LIBCPP_INLINE_VISIBILITY
1588uintmax_t hard_link_count(const path& __p, error_code& __ec) _NOEXCEPT {
1589 return __hard_link_count(__p, &__ec);
1590}
1591
1592inline _LIBCPP_INLINE_VISIBILITY
1593bool is_block_file(file_status __s) _NOEXCEPT {
1594 return __s.type() == file_type::block;
1595}
1596
1597inline _LIBCPP_INLINE_VISIBILITY
1598bool is_block_file(const path& __p) {
1599 return is_block_file(__status(__p));
1600}
1601
1602inline _LIBCPP_INLINE_VISIBILITY
1603bool is_block_file(const path& __p, error_code& __ec) _NOEXCEPT {
1604 return is_block_file(__status(__p, &__ec));
1605}
1606
1607inline _LIBCPP_INLINE_VISIBILITY
1608bool is_character_file(file_status __s) _NOEXCEPT {
1609 return __s.type() == file_type::character;
1610}
1611
1612inline _LIBCPP_INLINE_VISIBILITY
1613bool is_character_file(const path& __p) {
1614 return is_character_file(__status(__p));
1615}
1616
1617inline _LIBCPP_INLINE_VISIBILITY
1618bool is_character_file(const path& __p, error_code& __ec) _NOEXCEPT {
1619 return is_character_file(__status(__p, &__ec));
1620}
1621
1622inline _LIBCPP_INLINE_VISIBILITY
1623bool is_directory(file_status __s) _NOEXCEPT {
1624 return __s.type() == file_type::directory;
1625}
1626
1627inline _LIBCPP_INLINE_VISIBILITY
1628bool is_directory(const path& __p) {
1629 return is_directory(__status(__p));
1630}
1631
1632inline _LIBCPP_INLINE_VISIBILITY
1633bool is_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1634 return is_directory(__status(__p, &__ec));
1635}
1636
1637inline _LIBCPP_INLINE_VISIBILITY
1638bool is_empty(const path& __p) {
1639 return __fs_is_empty(__p);
1640}
1641
1642inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001643bool is_empty(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001644 return __fs_is_empty(__p, &__ec);
1645}
1646
1647inline _LIBCPP_INLINE_VISIBILITY
1648bool is_fifo(file_status __s) _NOEXCEPT {
1649 return __s.type() == file_type::fifo;
1650}
1651inline _LIBCPP_INLINE_VISIBILITY
1652bool is_fifo(const path& __p) {
1653 return is_fifo(__status(__p));
1654}
1655
1656inline _LIBCPP_INLINE_VISIBILITY
1657bool is_fifo(const path& __p, error_code& __ec) _NOEXCEPT {
1658 return is_fifo(__status(__p, &__ec));
1659}
1660
1661inline _LIBCPP_INLINE_VISIBILITY
1662bool is_regular_file(file_status __s) _NOEXCEPT {
1663 return __s.type() == file_type::regular;
1664}
1665
1666inline _LIBCPP_INLINE_VISIBILITY
1667bool is_regular_file(const path& __p) {
1668 return is_regular_file(__status(__p));
1669}
1670
1671inline _LIBCPP_INLINE_VISIBILITY
1672bool is_regular_file(const path& __p, error_code& __ec) _NOEXCEPT {
1673 return is_regular_file(__status(__p, &__ec));
1674}
1675
1676inline _LIBCPP_INLINE_VISIBILITY
1677bool is_socket(file_status __s) _NOEXCEPT {
1678 return __s.type() == file_type::socket;
1679}
1680
1681inline _LIBCPP_INLINE_VISIBILITY
1682bool is_socket(const path& __p) {
1683 return is_socket(__status(__p));
1684}
1685
1686inline _LIBCPP_INLINE_VISIBILITY
1687bool is_socket(const path& __p, error_code& __ec) _NOEXCEPT {
1688 return is_socket(__status(__p, &__ec));
1689}
1690
1691inline _LIBCPP_INLINE_VISIBILITY
1692bool is_symlink(file_status __s) _NOEXCEPT {
1693 return __s.type() == file_type::symlink;
1694}
1695
1696inline _LIBCPP_INLINE_VISIBILITY
1697bool is_symlink(const path& __p) {
1698 return is_symlink(__symlink_status(__p));
1699}
1700
1701inline _LIBCPP_INLINE_VISIBILITY
1702bool is_symlink(const path& __p, error_code& __ec) _NOEXCEPT {
1703 return is_symlink(__symlink_status(__p, &__ec));
1704}
1705
1706inline _LIBCPP_INLINE_VISIBILITY
1707bool is_other(file_status __s) _NOEXCEPT {
1708 return exists(__s)
1709 && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s);
1710}
1711
1712inline _LIBCPP_INLINE_VISIBILITY
1713bool is_other(const path& __p) {
1714 return is_other(__status(__p));
1715}
1716
1717inline _LIBCPP_INLINE_VISIBILITY
1718bool is_other(const path& __p, error_code& __ec) _NOEXCEPT {
1719 return is_other(__status(__p, &__ec));
1720}
1721
1722inline _LIBCPP_INLINE_VISIBILITY
1723file_time_type last_write_time(const path& __p) {
1724 return __last_write_time(__p);
1725}
1726
1727inline _LIBCPP_INLINE_VISIBILITY
1728file_time_type last_write_time(const path& __p, error_code& __ec) _NOEXCEPT {
1729 return __last_write_time(__p, &__ec);
1730}
1731
1732inline _LIBCPP_INLINE_VISIBILITY
1733void last_write_time(const path& __p, file_time_type __t) {
1734 __last_write_time(__p, __t);
1735}
1736
1737inline _LIBCPP_INLINE_VISIBILITY
1738void last_write_time(const path& __p, file_time_type __t, error_code& __ec) _NOEXCEPT {
1739 __last_write_time(__p, __t, &__ec);
1740}
1741
1742inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf2c93732018-03-26 06:23:55 +00001743void permissions(const path& __p, perms __prms,
1744 perm_options __opts = perm_options::replace) {
1745 __permissions(__p, __prms, __opts);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001746}
1747
1748inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf2c93732018-03-26 06:23:55 +00001749void permissions(const path& __p, perms __prms, error_code& __ec) _NOEXCEPT {
1750 __permissions(__p, __prms, perm_options::replace, &__ec);
1751}
1752
1753inline _LIBCPP_INLINE_VISIBILITY
1754void permissions(const path& __p, perms __prms, perm_options __opts,
1755 error_code& __ec) {
1756 __permissions(__p, __prms, __opts, &__ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001757}
1758
1759inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1e34c762018-04-02 23:03:41 +00001760path proximate(const path& __p, const path& __base, error_code& __ec) {
1761 path __tmp = __weakly_canonical(__p, &__ec);
1762 if (__ec)
1763 return {};
1764 path __tmp_base = __weakly_canonical(__base, &__ec);
1765 if (__ec)
1766 return {};
1767 return __tmp.lexically_proximate(__tmp_base);
1768}
1769
1770inline _LIBCPP_INLINE_VISIBILITY
1771path proximate(const path& __p, error_code& __ec) {
1772 return proximate(__p, current_path(), __ec);
1773}
1774
1775inline _LIBCPP_INLINE_VISIBILITY
1776path proximate(const path& __p, const path& __base = current_path()) {
1777 return __weakly_canonical(__p).lexically_proximate(__weakly_canonical(__base));
1778}
1779
1780inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001781path read_symlink(const path& __p) {
1782 return __read_symlink(__p);
1783}
1784
1785inline _LIBCPP_INLINE_VISIBILITY
1786path read_symlink(const path& __p, error_code& __ec) {
1787 return __read_symlink(__p, &__ec);
1788}
1789
Eric Fiselier1e34c762018-04-02 23:03:41 +00001790
1791inline _LIBCPP_INLINE_VISIBILITY
1792path relative(const path& __p, const path& __base, error_code& __ec) {
1793 path __tmp = __weakly_canonical(__p, &__ec);
1794 if (__ec)
1795 return path();
1796 path __tmpbase = __weakly_canonical(__base, &__ec);
1797 if (__ec)
1798 return path();
1799 return __tmp.lexically_relative(__tmpbase);
1800}
1801
1802inline _LIBCPP_INLINE_VISIBILITY
1803path relative(const path& __p, error_code& __ec) {
1804 return relative(__p, current_path(), __ec);
1805}
1806
1807inline _LIBCPP_INLINE_VISIBILITY
1808path relative(const path& __p, const path& __base=current_path()) {
1809 return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
1810}
1811
1812
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001813inline _LIBCPP_INLINE_VISIBILITY
1814bool remove(const path& __p) {
1815 return __remove(__p);
1816}
1817
1818inline _LIBCPP_INLINE_VISIBILITY
1819bool remove(const path& __p, error_code& __ec) _NOEXCEPT {
1820 return __remove(__p, &__ec);
1821}
1822
1823inline _LIBCPP_INLINE_VISIBILITY
1824uintmax_t remove_all(const path& __p) {
1825 return __remove_all(__p);
1826}
1827
1828inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001829uintmax_t remove_all(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001830 return __remove_all(__p, &__ec);
1831}
1832
1833inline _LIBCPP_INLINE_VISIBILITY
1834void rename(const path& __from, const path& __to) {
1835 return __rename(__from, __to);
1836}
1837
1838inline _LIBCPP_INLINE_VISIBILITY
1839void rename(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
1840 return __rename(__from, __to, &__ec);
1841}
1842
1843inline _LIBCPP_INLINE_VISIBILITY
1844void resize_file(const path& __p, uintmax_t __ns) {
1845 return __resize_file(__p, __ns);
1846}
1847
1848inline _LIBCPP_INLINE_VISIBILITY
1849void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) _NOEXCEPT {
1850 return __resize_file(__p, __ns, &__ec);
1851}
1852
1853inline _LIBCPP_INLINE_VISIBILITY
1854space_info space(const path& __p) {
1855 return __space(__p);
1856}
1857
1858inline _LIBCPP_INLINE_VISIBILITY
1859space_info space(const path& __p, error_code& __ec) _NOEXCEPT {
1860 return __space(__p, &__ec);
1861}
1862
1863inline _LIBCPP_INLINE_VISIBILITY
1864file_status status(const path& __p) {
1865 return __status(__p);
1866}
1867
1868inline _LIBCPP_INLINE_VISIBILITY
1869file_status status(const path& __p, error_code& __ec) _NOEXCEPT {
1870 return __status(__p, &__ec);
1871}
1872
1873inline _LIBCPP_INLINE_VISIBILITY
1874file_status symlink_status(const path& __p) {
1875 return __symlink_status(__p);
1876}
1877
1878inline _LIBCPP_INLINE_VISIBILITY
1879file_status symlink_status(const path& __p, error_code& __ec) _NOEXCEPT {
1880 return __symlink_status(__p, &__ec);
1881}
1882
1883inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001884path temp_directory_path() {
1885 return __temp_directory_path();
1886}
1887
1888inline _LIBCPP_INLINE_VISIBILITY
1889path temp_directory_path(error_code& __ec) {
1890 return __temp_directory_path(&__ec);
1891}
1892
Eric Fiselier1e34c762018-04-02 23:03:41 +00001893inline _LIBCPP_INLINE_VISIBILITY
1894path weakly_canonical(path const& __p) {
1895 return __weakly_canonical(__p);
1896}
1897
1898inline _LIBCPP_INLINE_VISIBILITY
1899path weakly_canonical(path const& __p, error_code& __ec) {
1900 return __weakly_canonical(__p, &__ec);
1901}
1902
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001903
1904class directory_entry
1905{
1906 typedef _VSTD_FS::path _Path;
1907
1908public:
1909 // constructors and destructors
1910 directory_entry() _NOEXCEPT = default;
1911 directory_entry(directory_entry const&) = default;
1912 directory_entry(directory_entry&&) _NOEXCEPT = default;
1913
1914 _LIBCPP_INLINE_VISIBILITY
1915 explicit directory_entry(_Path const& __p) : __p_(__p) {}
1916
1917 ~directory_entry() {}
1918
1919 directory_entry& operator=(directory_entry const&) = default;
1920 directory_entry& operator=(directory_entry&&) _NOEXCEPT = default;
1921
1922 _LIBCPP_INLINE_VISIBILITY
1923 void assign(_Path const& __p) {
1924 __p_ = __p;
1925 }
1926
1927 _LIBCPP_INLINE_VISIBILITY
1928 void replace_filename(_Path const& __p) {
1929 __p_ = __p_.parent_path() / __p;
1930 }
1931
1932 _LIBCPP_INLINE_VISIBILITY
1933 _Path const& path() const _NOEXCEPT {
1934 return __p_;
1935 }
1936
1937 _LIBCPP_INLINE_VISIBILITY
1938 operator const _Path&() const _NOEXCEPT {
1939 return __p_;
1940 }
1941
1942 _LIBCPP_INLINE_VISIBILITY
1943 file_status status() const {
1944 return _VSTD_FS::status(__p_);
1945 }
1946
1947 _LIBCPP_INLINE_VISIBILITY
1948 file_status status(error_code& __ec) const _NOEXCEPT {
1949 return _VSTD_FS::status(__p_, __ec);
1950 }
1951
1952 _LIBCPP_INLINE_VISIBILITY
1953 file_status symlink_status() const {
1954 return _VSTD_FS::symlink_status(__p_);
1955 }
1956
1957 _LIBCPP_INLINE_VISIBILITY
1958 file_status symlink_status(error_code& __ec) const _NOEXCEPT {
1959 return _VSTD_FS::symlink_status(__p_, __ec);
1960 }
1961
1962 _LIBCPP_INLINE_VISIBILITY
1963 bool operator< (directory_entry const& __rhs) const _NOEXCEPT {
1964 return __p_ < __rhs.__p_;
1965 }
1966
1967 _LIBCPP_INLINE_VISIBILITY
1968 bool operator==(directory_entry const& __rhs) const _NOEXCEPT {
1969 return __p_ == __rhs.__p_;
1970 }
1971
1972 _LIBCPP_INLINE_VISIBILITY
1973 bool operator!=(directory_entry const& __rhs) const _NOEXCEPT {
1974 return __p_ != __rhs.__p_;
1975 }
1976
1977 _LIBCPP_INLINE_VISIBILITY
1978 bool operator<=(directory_entry const& __rhs) const _NOEXCEPT {
1979 return __p_ <= __rhs.__p_;
1980 }
1981
1982 _LIBCPP_INLINE_VISIBILITY
1983 bool operator> (directory_entry const& __rhs) const _NOEXCEPT {
1984 return __p_ > __rhs.__p_;
1985 }
1986
1987 _LIBCPP_INLINE_VISIBILITY
1988 bool operator>=(directory_entry const& __rhs) const _NOEXCEPT {
1989 return __p_ >= __rhs.__p_;
1990 }
1991private:
1992 _Path __p_;
1993};
1994
1995
1996class directory_iterator;
1997class recursive_directory_iterator;
1998class __dir_stream;
1999
2000class __dir_element_proxy {
2001public:
2002
2003 inline _LIBCPP_INLINE_VISIBILITY
2004 directory_entry operator*() { return _VSTD::move(__elem_); }
2005
2006private:
2007 friend class directory_iterator;
2008 friend class recursive_directory_iterator;
2009 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
2010 __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {}
2011 directory_entry __elem_;
2012};
2013
2014class directory_iterator
2015{
2016public:
2017 typedef directory_entry value_type;
2018 typedef ptrdiff_t difference_type;
2019 typedef value_type const* pointer;
2020 typedef value_type const& reference;
2021 typedef input_iterator_tag iterator_category;
2022
2023public:
2024 //ctor & dtor
2025 directory_iterator() _NOEXCEPT
2026 { }
2027
2028 explicit directory_iterator(const path& __p)
2029 : directory_iterator(__p, nullptr)
2030 { }
2031
2032 directory_iterator(const path& __p, directory_options __opts)
2033 : directory_iterator(__p, nullptr, __opts)
2034 { }
2035
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002036 directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002037 : directory_iterator(__p, &__ec)
2038 { }
2039
2040 directory_iterator(const path& __p, directory_options __opts,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002041 error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002042 : directory_iterator(__p, &__ec, __opts)
2043 { }
2044
2045 directory_iterator(const directory_iterator&) = default;
2046 directory_iterator(directory_iterator&&) = default;
2047 directory_iterator& operator=(const directory_iterator&) = default;
2048
2049 directory_iterator& operator=(directory_iterator&& __o) _NOEXCEPT {
2050 // non-default implementation provided to support self-move assign.
2051 if (this != &__o) {
2052 __imp_ = _VSTD::move(__o.__imp_);
2053 }
2054 return *this;
2055 }
2056
2057 ~directory_iterator() = default;
2058
2059 const directory_entry& operator*() const {
2060 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002061 return __dereference();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002062 }
2063
2064 const directory_entry* operator->() const
2065 { return &**this; }
2066
2067 directory_iterator& operator++()
2068 { return __increment(); }
2069
2070 __dir_element_proxy operator++(int) {
2071 __dir_element_proxy __p(**this);
2072 __increment();
2073 return __p;
2074 }
2075
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002076 directory_iterator& increment(error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002077 { return __increment(&__ec); }
2078
2079private:
Eric Fiselier03f7d102016-09-16 00:07:16 +00002080 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002081 friend bool operator==(const directory_iterator& __lhs,
2082 const directory_iterator& __rhs) _NOEXCEPT;
2083
2084 // construct the dir_stream
2085 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002086 directory_iterator(const path&, error_code *,
2087 directory_options = directory_options::none);
2088
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002089 _LIBCPP_FUNC_VIS
2090 directory_iterator& __increment(error_code * __ec = nullptr);
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002091
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002092 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002093 const directory_entry& __dereference() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002094
2095private:
2096 shared_ptr<__dir_stream> __imp_;
2097};
2098
2099
2100inline _LIBCPP_INLINE_VISIBILITY
2101bool operator==(const directory_iterator& __lhs,
2102 const directory_iterator& __rhs) _NOEXCEPT {
2103 return __lhs.__imp_ == __rhs.__imp_;
2104}
2105
2106inline _LIBCPP_INLINE_VISIBILITY
2107bool operator!=(const directory_iterator& __lhs,
2108 const directory_iterator& __rhs) _NOEXCEPT {
2109 return !(__lhs == __rhs);
2110}
2111
2112// enable directory_iterator range-based for statements
2113inline _LIBCPP_INLINE_VISIBILITY
2114directory_iterator begin(directory_iterator __iter) _NOEXCEPT {
2115 return __iter;
2116}
2117
2118inline _LIBCPP_INLINE_VISIBILITY
2119directory_iterator end(const directory_iterator&) _NOEXCEPT {
2120 return directory_iterator();
2121}
2122
2123class recursive_directory_iterator {
2124public:
2125 using value_type = directory_entry;
2126 using difference_type = std::ptrdiff_t;
2127 using pointer = directory_entry const *;
2128 using reference = directory_entry const &;
2129 using iterator_category = std::input_iterator_tag;
2130
2131public:
2132 // constructors and destructor
2133 _LIBCPP_INLINE_VISIBILITY
2134 recursive_directory_iterator() _NOEXCEPT
2135 : __rec_(false)
2136 {}
2137
2138 _LIBCPP_INLINE_VISIBILITY
2139 explicit recursive_directory_iterator(const path& __p,
2140 directory_options __xoptions = directory_options::none)
2141 : recursive_directory_iterator(__p, __xoptions, nullptr)
2142 { }
2143
2144 _LIBCPP_INLINE_VISIBILITY
2145 recursive_directory_iterator(const path& __p,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002146 directory_options __xoptions, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002147 : recursive_directory_iterator(__p, __xoptions, &__ec)
2148 { }
2149
2150 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002151 recursive_directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002152 : recursive_directory_iterator(__p, directory_options::none, &__ec)
2153 { }
2154
2155 recursive_directory_iterator(const recursive_directory_iterator&) = default;
2156 recursive_directory_iterator(recursive_directory_iterator&&) = default;
2157
2158 recursive_directory_iterator &
2159 operator=(const recursive_directory_iterator&) = default;
2160
2161 _LIBCPP_INLINE_VISIBILITY
2162 recursive_directory_iterator &
2163 operator=(recursive_directory_iterator&& __o) noexcept {
2164 // non-default implementation provided to support self-move assign.
2165 if (this != &__o) {
2166 __imp_ = _VSTD::move(__o.__imp_);
2167 __rec_ = __o.__rec_;
2168 }
2169 return *this;
2170 }
2171
2172 ~recursive_directory_iterator() = default;
2173
2174 _LIBCPP_INLINE_VISIBILITY
2175 const directory_entry& operator*() const
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002176 { return __dereference(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002177
2178 _LIBCPP_INLINE_VISIBILITY
2179 const directory_entry* operator->() const
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002180 { return &__dereference(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002181
2182 recursive_directory_iterator& operator++()
2183 { return __increment(); }
2184
2185 _LIBCPP_INLINE_VISIBILITY
2186 __dir_element_proxy operator++(int) {
2187 __dir_element_proxy __p(**this);
2188 __increment();
2189 return __p;
2190 }
2191
2192 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002193 recursive_directory_iterator& increment(error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002194 { return __increment(&__ec); }
2195
2196 _LIBCPP_FUNC_VIS directory_options options() const;
2197 _LIBCPP_FUNC_VIS int depth() const;
2198
2199 _LIBCPP_INLINE_VISIBILITY
2200 void pop() { __pop(); }
2201
2202 _LIBCPP_INLINE_VISIBILITY
2203 void pop(error_code& __ec)
2204 { __pop(&__ec); }
2205
2206 _LIBCPP_INLINE_VISIBILITY
2207 bool recursion_pending() const
2208 { return __rec_; }
2209
2210 _LIBCPP_INLINE_VISIBILITY
2211 void disable_recursion_pending()
2212 { __rec_ = false; }
2213
2214private:
2215 recursive_directory_iterator(const path& __p, directory_options __opt,
2216 error_code *__ec);
2217
2218 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002219 const directory_entry& __dereference() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002220
2221 _LIBCPP_FUNC_VIS
2222 bool __try_recursion(error_code* __ec);
2223
2224 _LIBCPP_FUNC_VIS
2225 void __advance(error_code* __ec=nullptr);
2226
2227 _LIBCPP_FUNC_VIS
2228 recursive_directory_iterator& __increment(error_code *__ec=nullptr);
2229
2230 _LIBCPP_FUNC_VIS
2231 void __pop(error_code* __ec=nullptr);
2232
Eric Fiselier03f7d102016-09-16 00:07:16 +00002233 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002234 friend bool operator==(const recursive_directory_iterator&,
2235 const recursive_directory_iterator&) _NOEXCEPT;
2236
2237 struct __shared_imp;
2238 shared_ptr<__shared_imp> __imp_;
2239 bool __rec_;
2240}; // class recursive_directory_iterator
2241
2242
Eric Fiselier03f7d102016-09-16 00:07:16 +00002243inline _LIBCPP_INLINE_VISIBILITY
2244bool operator==(const recursive_directory_iterator& __lhs,
2245 const recursive_directory_iterator& __rhs) _NOEXCEPT
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002246{
2247 return __lhs.__imp_ == __rhs.__imp_;
2248}
2249
2250_LIBCPP_INLINE_VISIBILITY
2251inline bool operator!=(const recursive_directory_iterator& __lhs,
2252 const recursive_directory_iterator& __rhs) _NOEXCEPT
2253{
2254 return !(__lhs == __rhs);
2255}
2256// enable recursive_directory_iterator range-based for statements
2257inline _LIBCPP_INLINE_VISIBILITY
2258recursive_directory_iterator begin(recursive_directory_iterator __iter) _NOEXCEPT {
2259 return __iter;
2260}
2261
2262inline _LIBCPP_INLINE_VISIBILITY
2263recursive_directory_iterator end(const recursive_directory_iterator&) _NOEXCEPT {
2264 return recursive_directory_iterator();
2265}
2266
2267_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
2268
2269#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM