blob: 411b98121f060d81e61890910a38ce050271beb1 [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
724 // constructors and destructor
725 _LIBCPP_INLINE_VISIBILITY path() _NOEXCEPT {}
726 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
727 _LIBCPP_INLINE_VISIBILITY path(path&& __p) _NOEXCEPT : __pn_(_VSTD::move(__p.__pn_)) {}
728
729 _LIBCPP_INLINE_VISIBILITY
730 path(string_type&& __s) _NOEXCEPT : __pn_(_VSTD::move(__s)) {}
731
732 template <
733 class _Source,
734 class = _EnableIfPathable<_Source, void>
735 >
736 path(const _Source& __src) {
737 _SourceCVT<_Source>::__append_source(__pn_, __src);
738 }
739
740 template <class _InputIt>
741 path(_InputIt __first, _InputIt __last) {
742 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
743 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
744 }
745
746 // TODO Implement locale conversions.
747 template <class _Source,
748 class = _EnableIfPathable<_Source, void>
749 >
750 path(const _Source& __src, const locale& __loc);
751 template <class _InputIt>
752 path(_InputIt __first, _InputIt _last, const locale& __loc);
753
754 _LIBCPP_INLINE_VISIBILITY
755 ~path() = default;
756
757 // assignments
758 _LIBCPP_INLINE_VISIBILITY
759 path& operator=(const path& __p) {
760 __pn_ = __p.__pn_;
761 return *this;
762 }
763
764 _LIBCPP_INLINE_VISIBILITY
765 path& operator=(path&& __p) _NOEXCEPT {
766 __pn_ = _VSTD::move(__p.__pn_);
767 return *this;
768 }
769
Eric Fiselierf2b48892017-01-18 05:48:55 +0000770 template <class = void>
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000771 _LIBCPP_INLINE_VISIBILITY
772 path& operator=(string_type&& __s) _NOEXCEPT {
773 __pn_ = _VSTD::move(__s);
774 return *this;
775 }
776
777 _LIBCPP_INLINE_VISIBILITY
778 path& assign(string_type&& __s) _NOEXCEPT {
779 __pn_ = _VSTD::move(__s);
780 return *this;
781 }
782
783 template <class _Source>
784 _LIBCPP_INLINE_VISIBILITY
785 _EnableIfPathable<_Source>
786 operator=(const _Source& __src)
787 { return this->assign(__src); }
788
789
790 template <class _Source>
791 _EnableIfPathable<_Source>
792 assign(const _Source& __src) {
793 __pn_.clear();
794 _SourceCVT<_Source>::__append_source(__pn_, __src);
795 return *this;
796 }
797
798 template <class _InputIt>
799 path& assign(_InputIt __first, _InputIt __last) {
800 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
801 __pn_.clear();
802 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
803 return *this;
804 }
805
806private:
807 template <class _ECharT>
Eric Fiselier1e34c762018-04-02 23:03:41 +0000808 static bool __source_is_absolute(_ECharT __first_or_null) {
809 return __is_separator(__first_or_null);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000810 }
811
812public:
813 // appends
814 path& operator/=(const path& __p) {
Eric Fiselier1e34c762018-04-02 23:03:41 +0000815 if (__p.is_absolute()) {
816 __pn_ = __p.__pn_;
817 return *this;
818 }
819 if (has_filename())
820 __pn_ += preferred_separator;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000821 __pn_ += __p.native();
822 return *this;
823 }
824
Eric Fiselier1e34c762018-04-02 23:03:41 +0000825 // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
826 // is known at compile time to be "/' since the user almost certainly intended
827 // to append a separator instead of overwriting the path with "/"
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000828 template <class _Source>
829 _LIBCPP_INLINE_VISIBILITY
830 _EnableIfPathable<_Source>
831 operator/=(const _Source& __src) {
832 return this->append(__src);
833 }
834
835 template <class _Source>
836 _EnableIfPathable<_Source>
837 append(const _Source& __src) {
838 using _Traits = __is_pathable<_Source>;
839 using _CVT = _PathCVT<_SourceChar<_Source>>;
Eric Fiselier1e34c762018-04-02 23:03:41 +0000840 if (__source_is_absolute(_Traits::__first_or_null(__src)))
841 __pn_.clear();
842 else if (has_filename())
843 __pn_ += preferred_separator;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000844 _CVT::__append_source(__pn_, __src);
845 return *this;
846 }
847
848 template <class _InputIt>
849 path& append(_InputIt __first, _InputIt __last) {
850 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
851 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
852 using _CVT = _PathCVT<_ItVal>;
Eric Fiselier1e34c762018-04-02 23:03:41 +0000853 if (__first != __last && __source_is_absolute(*__first))
854 __pn_.clear();
855 else if (has_filename())
856 __pn_ += preferred_separator;
857 _CVT::__append_range(__pn_, __first, __last);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000858 return *this;
859 }
860
861 // concatenation
862 _LIBCPP_INLINE_VISIBILITY
863 path& operator+=(const path& __x) {
864 __pn_ += __x.__pn_;
865 return *this;
866 }
867
868 _LIBCPP_INLINE_VISIBILITY
869 path& operator+=(const string_type& __x) {
870 __pn_ += __x;
871 return *this;
872 }
873
874 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000875 path& operator+=(__string_view __x) {
876 __pn_ += __x;
877 return *this;
878 }
879
880 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000881 path& operator+=(const value_type* __x) {
882 __pn_ += __x;
883 return *this;
884 }
885
886 _LIBCPP_INLINE_VISIBILITY
887 path& operator+=(value_type __x) {
888 __pn_ += __x;
889 return *this;
890 }
891
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000892 template <class _ECharT>
893 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
894 operator+=(_ECharT __x)
895 {
896 basic_string<_ECharT> __tmp;
897 __tmp += __x;
898 _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
899 return *this;
900 }
901
902 template <class _Source>
903 _EnableIfPathable<_Source>
904 operator+=(const _Source& __x) {
905 return this->concat(__x);
906 }
907
908 template <class _Source>
909 _EnableIfPathable<_Source>
910 concat(const _Source& __x) {
911 _SourceCVT<_Source>::__append_source(__pn_, __x);
912 return *this;
913 }
914
915 template <class _InputIt>
916 path& concat(_InputIt __first, _InputIt __last) {
917 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
918 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
919 return *this;
920 }
921
922 // modifiers
923 _LIBCPP_INLINE_VISIBILITY
924 void clear() _NOEXCEPT {
925 __pn_.clear();
926 }
927
928 path& make_preferred() { return *this; }
Eric Fiselier620a9a52016-10-15 22:37:42 +0000929
930 _LIBCPP_INLINE_VISIBILITY
931 path& remove_filename() {
Eric Fiselier1e34c762018-04-02 23:03:41 +0000932 auto __fname = __filename();
933 if (!__fname.empty())
934 __pn_.erase(__fname.data() - __pn_.data());
Eric Fiselier620a9a52016-10-15 22:37:42 +0000935 return *this;
936 }
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000937
938 path& replace_filename(const path& __replacement) {
939 remove_filename();
940 return (*this /= __replacement);
941 }
942
943 path& replace_extension(const path& __replacement = path());
944
945 _LIBCPP_INLINE_VISIBILITY
946 void swap(path& __rhs) _NOEXCEPT {
947 __pn_.swap(__rhs.__pn_);
948 }
949
Eric Fiselier1e34c762018-04-02 23:03:41 +0000950 // private helper to allow reserving memory in the path
951 _LIBCPP_INLINE_VISIBILITY
952 void __reserve(size_t __s) { __pn_.reserve(__s); }
953
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000954 // native format observers
955 _LIBCPP_INLINE_VISIBILITY
956 const string_type& native() const _NOEXCEPT {
957 return __pn_;
958 }
959
960 _LIBCPP_INLINE_VISIBILITY
961 const value_type* c_str() const _NOEXCEPT { return __pn_.c_str(); }
962
963 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
964
965 template <class _ECharT, class _Traits = char_traits<_ECharT>,
966 class _Allocator = allocator<_ECharT> >
967 basic_string<_ECharT, _Traits, _Allocator>
968 string(const _Allocator& __a = _Allocator()) const {
969 using _CVT = __widen_from_utf8<sizeof(_ECharT)*__CHAR_BIT__>;
970 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
971 _Str __s(__a);
972 __s.reserve(__pn_.size());
973 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
974 return __s;
975 }
976
977 _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
978 _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const { return string<wchar_t>(); }
979 _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
980 _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { return string<char16_t>(); }
981 _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { return string<char32_t>(); }
982
983 // generic format observers
984 template <class _ECharT, class _Traits = char_traits<_ECharT>,
985 class _Allocator = allocator<_ECharT>
986 >
987 basic_string<_ECharT, _Traits, _Allocator>
988 generic_string(const _Allocator& __a = _Allocator()) const {
989 return string<_ECharT, _Traits, _Allocator>(__a);
990 }
991
992 std::string generic_string() const { return __pn_; }
993 std::wstring generic_wstring() const { return string<wchar_t>(); }
994 std::string generic_u8string() const { return __pn_; }
995 std::u16string generic_u16string() const { return string<char16_t>(); }
996 std::u32string generic_u32string() const { return string<char32_t>(); }
997
998private:
Saleem Abdulrasool52241cb2017-01-30 03:58:26 +0000999 int __compare(__string_view) const;
1000 __string_view __root_name() const;
1001 __string_view __root_directory() const;
1002 __string_view __root_path_raw() const;
1003 __string_view __relative_path() const;
1004 __string_view __parent_path() const;
1005 __string_view __filename() const;
1006 __string_view __stem() const;
1007 __string_view __extension() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001008
1009public:
1010 // compare
Eric Fiselier2645dbe2016-07-23 03:10:56 +00001011 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const _NOEXCEPT { return __compare(__p.__pn_);}
1012 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); }
1013 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001014 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { return __compare(__s); }
1015
1016 // decomposition
Eric Fiselier2645dbe2016-07-23 03:10:56 +00001017 _LIBCPP_INLINE_VISIBILITY path root_name() const { return string_type(__root_name()); }
1018 _LIBCPP_INLINE_VISIBILITY path root_directory() const { return string_type(__root_directory()); }
1019 _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(string_type(__root_directory())); }
1020 _LIBCPP_INLINE_VISIBILITY path relative_path() const { return string_type(__relative_path()); }
1021 _LIBCPP_INLINE_VISIBILITY path parent_path() const { return string_type(__parent_path()); }
1022 _LIBCPP_INLINE_VISIBILITY path filename() const { return string_type(__filename()); }
1023 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem());}
1024 _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001025
1026 // query
Marshall Clowbc6989b2017-11-16 05:48:32 +00001027 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1028 bool empty() const _NOEXCEPT { return __pn_.empty(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001029
1030 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); }
1031 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); }
Eric Fiselier620a9a52016-10-15 22:37:42 +00001032 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !__root_path_raw().empty(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001033 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { return !__relative_path().empty(); }
1034 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { return !__parent_path().empty(); }
1035 _LIBCPP_INLINE_VISIBILITY bool has_filename() const { return !__filename().empty(); }
1036 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
1037 _LIBCPP_INLINE_VISIBILITY bool has_extension() const { return !__extension().empty(); }
1038
1039 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { return has_root_directory(); }
1040 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
1041
Eric Fiselier1e34c762018-04-02 23:03:41 +00001042 // relative paths
1043 path lexically_normal() const;
1044 path lexically_relative(const path& __base) const;
1045
1046 _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
1047 path __result = this->lexically_relative(__base);
1048 if (__result.native().empty())
1049 return *this;
1050 return __result;
1051 }
1052
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001053 // iterators
1054 class _LIBCPP_TYPE_VIS iterator;
1055 typedef iterator const_iterator;
1056
Saleem Abdulrasool52241cb2017-01-30 03:58:26 +00001057 iterator begin() const;
1058 iterator end() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001059
Eric Fiselier0b47a652018-02-04 03:10:53 +00001060
1061 template <class _CharT, class _Traits>
1062 _LIBCPP_INLINE_VISIBILITY
1063 friend typename enable_if<is_same<_CharT, char>::value &&
1064 is_same<_Traits, char_traits<char>>::value,
1065 basic_ostream<_CharT, _Traits>&
1066 >::type
1067 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1068 __os << std::__quoted(__p.native());
1069 return __os;
1070 }
1071
1072 template <class _CharT, class _Traits>
1073 _LIBCPP_INLINE_VISIBILITY
1074 friend typename enable_if<!is_same<_CharT, char>::value ||
1075 !is_same<_Traits, char_traits<char>>::value,
1076 basic_ostream<_CharT, _Traits>&
1077 >::type
1078 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1079 __os << std::__quoted(__p.string<_CharT, _Traits>());
1080 return __os;
1081 }
1082
1083 template <class _CharT, class _Traits>
1084 _LIBCPP_INLINE_VISIBILITY
1085 friend basic_istream<_CharT, _Traits>&
1086 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
1087 {
1088 basic_string<_CharT, _Traits> __tmp;
1089 __is >> __quoted(__tmp);
1090 __p = __tmp;
1091 return __is;
1092 }
1093
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001094private:
1095 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2645dbe2016-07-23 03:10:56 +00001096 path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001097 string_type __pn_;
1098};
1099
1100inline _LIBCPP_ALWAYS_INLINE
1101void swap(path& __lhs, path& __rhs) _NOEXCEPT {
1102 __lhs.swap(__rhs);
1103}
1104
1105_LIBCPP_FUNC_VIS
1106size_t hash_value(const path& __p) _NOEXCEPT;
1107
1108inline _LIBCPP_INLINE_VISIBILITY
1109bool operator==(const path& __lhs, const path& __rhs) _NOEXCEPT
1110{ return __lhs.compare(__rhs) == 0; }
1111
1112inline _LIBCPP_INLINE_VISIBILITY
1113bool operator!=(const path& __lhs, const path& __rhs) _NOEXCEPT
1114{ return __lhs.compare(__rhs) != 0; }
1115
1116inline _LIBCPP_INLINE_VISIBILITY
1117bool operator<(const path& __lhs, const path& __rhs) _NOEXCEPT
1118{ return __lhs.compare(__rhs) < 0; }
1119
1120inline _LIBCPP_INLINE_VISIBILITY
1121bool operator<=(const path& __lhs, const path& __rhs) _NOEXCEPT
1122{ return __lhs.compare(__rhs) <= 0; }
1123
1124inline _LIBCPP_INLINE_VISIBILITY
1125bool operator>(const path& __lhs, const path& __rhs) _NOEXCEPT
1126{ return __lhs.compare(__rhs) > 0; }
1127
1128inline _LIBCPP_INLINE_VISIBILITY
1129bool operator>=(const path& __lhs, const path& __rhs) _NOEXCEPT
1130{ return __lhs.compare(__rhs) >= 0; }
1131
1132inline _LIBCPP_INLINE_VISIBILITY
1133path operator/(const path& __lhs, const path& __rhs) {
1134 return path(__lhs) /= __rhs;
1135}
1136
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001137template <class _Source>
1138_LIBCPP_INLINE_VISIBILITY
1139typename enable_if<__is_pathable<_Source>::value, path>::type
1140u8path(const _Source& __s){
1141 static_assert(is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1142 "u8path(Source const&) requires Source have a character type of type 'char'");
1143 return path(__s);
1144}
1145
1146template <class _InputIt>
1147_LIBCPP_INLINE_VISIBILITY
1148typename enable_if<__is_pathable<_InputIt>::value, path>::type
1149u8path(_InputIt __f, _InputIt __l) {
1150 static_assert(is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1151 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1152 return path(__f, __l);
1153}
1154
1155class _LIBCPP_TYPE_VIS path::iterator
1156{
1157public:
1158 typedef bidirectional_iterator_tag iterator_category;
Eric Fiselier08673732017-04-04 01:05:59 +00001159
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001160 typedef path value_type;
1161 typedef std::ptrdiff_t difference_type;
1162 typedef const path* pointer;
1163 typedef const path& reference;
Eric Fiselier706e2c72017-04-13 02:54:13 +00001164
1165 typedef void __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001166public:
1167 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier271a19e2016-10-30 23:30:38 +00001168 iterator() : __stashed_elem_(), __path_ptr_(nullptr),
1169 __entry_(), __state_(__singular) {}
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001170
1171 iterator(const iterator&) = default;
1172 ~iterator() = default;
1173
1174 iterator& operator=(const iterator&) = default;
1175
1176 _LIBCPP_INLINE_VISIBILITY
1177 reference operator*() const {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001178 return __stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001179 }
1180
1181 _LIBCPP_INLINE_VISIBILITY
1182 pointer operator->() const {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001183 return &__stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001184 }
1185
1186 _LIBCPP_INLINE_VISIBILITY
1187 iterator& operator++() {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001188 _LIBCPP_ASSERT(__state_ != __singular,
1189 "attempting to increment a singular iterator");
1190 _LIBCPP_ASSERT(__state_ != __at_end,
1191 "attempting to increment the end iterator");
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001192 return __increment();
1193 }
1194
1195 _LIBCPP_INLINE_VISIBILITY
1196 iterator operator++(int) {
1197 iterator __it(*this);
1198 this->operator++();
1199 return __it;
1200 }
1201
1202 _LIBCPP_INLINE_VISIBILITY
1203 iterator& operator--() {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001204 _LIBCPP_ASSERT(__state_ != __singular,
1205 "attempting to decrement a singular iterator");
1206 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
1207 "attempting to decrement the begin iterator");
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001208 return __decrement();
1209 }
1210
1211 _LIBCPP_INLINE_VISIBILITY
1212 iterator operator--(int) {
1213 iterator __it(*this);
1214 this->operator--();
1215 return __it;
1216 }
1217
1218private:
1219 friend class path;
Eric Fiselier03f7d102016-09-16 00:07:16 +00001220
Eric Fiselier271a19e2016-10-30 23:30:38 +00001221 static constexpr unsigned char __singular = 0;
1222 static constexpr unsigned char __at_end = 6;
1223
Eric Fiselier03f7d102016-09-16 00:07:16 +00001224 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001225 friend bool operator==(const iterator&, const iterator&);
1226
Saleem Abdulrasool52241cb2017-01-30 03:58:26 +00001227 iterator& __increment();
1228 iterator& __decrement();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001229
Eric Fiselier271a19e2016-10-30 23:30:38 +00001230 path __stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001231 const path* __path_ptr_;
Eric Fiselier271a19e2016-10-30 23:30:38 +00001232 path::__string_view __entry_;
1233 unsigned char __state_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001234};
1235
1236inline _LIBCPP_INLINE_VISIBILITY
1237bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) {
1238 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
Eric Fiselier271a19e2016-10-30 23:30:38 +00001239 __lhs.__entry_.data() == __rhs.__entry_.data();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001240}
1241
1242inline _LIBCPP_INLINE_VISIBILITY
1243bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) {
1244 return !(__lhs == __rhs);
1245}
1246
1247class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error
1248{
1249public:
1250 _LIBCPP_INLINE_VISIBILITY
1251 filesystem_error(const string& __what, error_code __ec)
1252 : system_error(__ec, __what),
1253 __paths_(make_shared<_Storage>(path(), path()))
1254 {}
1255
1256 _LIBCPP_INLINE_VISIBILITY
1257 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1258 : system_error(__ec, __what),
1259 __paths_(make_shared<_Storage>(__p1, path()))
1260 {}
1261
1262 _LIBCPP_INLINE_VISIBILITY
1263 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1264 error_code __ec)
1265 : system_error(__ec, __what),
1266 __paths_(make_shared<_Storage>(__p1, __p2))
1267 {}
1268
1269 _LIBCPP_INLINE_VISIBILITY
1270 const path& path1() const _NOEXCEPT {
1271 return __paths_->first;
1272 }
1273
1274 _LIBCPP_INLINE_VISIBILITY
1275 const path& path2() const _NOEXCEPT {
1276 return __paths_->second;
1277 }
1278
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001279 ~filesystem_error() override; // key function
1280
1281 // TODO(ericwf): Create a custom error message.
1282 //const char* what() const _NOEXCEPT;
1283
1284private:
1285 typedef pair<path, path> _Storage;
1286 shared_ptr<_Storage> __paths_;
1287};
1288
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001289template <class... _Args>
1290_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00001291#ifndef _LIBCPP_NO_EXCEPTIONS
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001292void __throw_filesystem_error(_Args && ...__args)
1293{
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001294 throw filesystem_error(std::forward<_Args>(__args)...);
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001295}
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00001296#else
1297void __throw_filesystem_error(_Args&&...)
1298{
1299 _VSTD::abort();
1300}
1301#endif
1302
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001303
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001304// operational functions
1305
1306_LIBCPP_FUNC_VIS
Eric Fiselier1e34c762018-04-02 23:03:41 +00001307path __absolute(const path&, error_code *__ec=nullptr);
1308_LIBCPP_FUNC_VIS
1309path __canonical(const path&, error_code *__ec=nullptr);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001310_LIBCPP_FUNC_VIS
1311void __copy(const path& __from, const path& __to, copy_options __opt,
1312 error_code *__ec=nullptr);
1313_LIBCPP_FUNC_VIS
1314bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1315 error_code *__ec=nullptr);
1316_LIBCPP_FUNC_VIS
1317void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1318 error_code *__ec=nullptr);
1319_LIBCPP_FUNC_VIS
1320bool __create_directories(const path& p, error_code *ec=nullptr);
1321_LIBCPP_FUNC_VIS
1322bool __create_directory(const path& p, error_code *ec=nullptr);
1323_LIBCPP_FUNC_VIS
1324bool __create_directory(const path& p, const path & attributes,
1325 error_code *ec=nullptr);
1326_LIBCPP_FUNC_VIS
1327void __create_directory_symlink(const path& __to, const path& __new_symlink,
1328 error_code *__ec=nullptr);
1329_LIBCPP_FUNC_VIS
1330void __create_hard_link(const path& __to, const path& __new_hard_link,
1331 error_code *__ec=nullptr);
1332_LIBCPP_FUNC_VIS
1333void __create_symlink(const path& __to, const path& __new_symlink,
1334 error_code *__ec=nullptr);
1335_LIBCPP_FUNC_VIS
1336path __current_path(error_code *__ec=nullptr);
1337_LIBCPP_FUNC_VIS
1338void __current_path(const path&, error_code *__ec=nullptr);
1339_LIBCPP_FUNC_VIS
1340bool __equivalent(const path&, const path&, error_code *__ec=nullptr);
1341_LIBCPP_FUNC_VIS
1342uintmax_t __file_size(const path&, error_code *__ec=nullptr);
1343_LIBCPP_FUNC_VIS
1344uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr);
1345_LIBCPP_FUNC_VIS
1346bool __fs_is_empty(const path& p, error_code *ec=nullptr);
1347_LIBCPP_FUNC_VIS
1348file_time_type __last_write_time(const path& p, error_code *ec=nullptr);
1349_LIBCPP_FUNC_VIS
1350void __last_write_time(const path& p, file_time_type new_time,
1351 error_code *ec=nullptr);
1352_LIBCPP_FUNC_VIS
Eric Fiselierf2c93732018-03-26 06:23:55 +00001353void __permissions(const path&, perms, perm_options, error_code* = nullptr);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001354_LIBCPP_FUNC_VIS
1355path __read_symlink(const path& p, error_code *ec=nullptr);
1356_LIBCPP_FUNC_VIS
1357bool __remove(const path& p, error_code *ec=nullptr);
1358_LIBCPP_FUNC_VIS
1359uintmax_t __remove_all(const path& p, error_code *ec=nullptr);
1360_LIBCPP_FUNC_VIS
1361void __rename(const path& from, const path& to, error_code *ec=nullptr);
1362_LIBCPP_FUNC_VIS
1363void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr);
1364_LIBCPP_FUNC_VIS
1365space_info __space(const path&, error_code *__ec=nullptr);
1366_LIBCPP_FUNC_VIS
1367file_status __status(const path&, error_code *__ec=nullptr);
1368_LIBCPP_FUNC_VIS
1369file_status __symlink_status(const path&, error_code *__ec=nullptr);
1370_LIBCPP_FUNC_VIS
1371path __system_complete(const path&, error_code *__ec=nullptr);
1372_LIBCPP_FUNC_VIS
1373path __temp_directory_path(error_code *__ec=nullptr);
Eric Fiselier1e34c762018-04-02 23:03:41 +00001374_LIBCPP_FUNC_VIS
1375path __weakly_canonical(path const& __p, error_code *__ec=nullptr);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001376
1377inline _LIBCPP_INLINE_VISIBILITY
1378path current_path() {
1379 return __current_path();
1380}
1381
1382inline _LIBCPP_INLINE_VISIBILITY
1383path current_path(error_code& __ec) {
1384 return __current_path(&__ec);
1385}
1386
1387inline _LIBCPP_INLINE_VISIBILITY
1388void current_path(const path& __p) {
1389 __current_path(__p);
1390}
1391
1392inline _LIBCPP_INLINE_VISIBILITY
1393void current_path(const path& __p, error_code& __ec) _NOEXCEPT {
1394 __current_path(__p, &__ec);
1395}
1396
Eric Fiselier1e34c762018-04-02 23:03:41 +00001397inline _LIBCPP_INLINE_VISIBILITY
1398path absolute(const path& __p) {
1399 return __absolute(__p);
1400}
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001401
1402inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1e34c762018-04-02 23:03:41 +00001403path absolute(const path& __p, error_code &__ec) {
1404 return __absolute(__p, &__ec);
1405}
1406
1407inline _LIBCPP_INLINE_VISIBILITY
1408path canonical(const path& __p) {
1409 return __canonical(__p);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001410}
1411
1412inline _LIBCPP_INLINE_VISIBILITY
1413path canonical(const path& __p, error_code& __ec) {
Eric Fiselier1e34c762018-04-02 23:03:41 +00001414 return __canonical(__p, &__ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001415}
1416
1417inline _LIBCPP_INLINE_VISIBILITY
1418void copy(const path& __from, const path& __to) {
1419 __copy(__from, __to, copy_options::none);
1420}
1421
1422inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001423void copy(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001424 __copy(__from, __to, copy_options::none, &__ec);
1425}
1426
1427inline _LIBCPP_INLINE_VISIBILITY
1428void copy(const path& __from, const path& __to, copy_options __opt) {
1429 __copy(__from, __to, __opt);
1430}
1431
1432inline _LIBCPP_INLINE_VISIBILITY
1433void copy(const path& __from, const path& __to,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001434 copy_options __opt, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001435 __copy(__from, __to, __opt, &__ec);
1436}
1437
1438inline _LIBCPP_INLINE_VISIBILITY
1439bool copy_file(const path& __from, const path& __to) {
1440 return __copy_file(__from, __to, copy_options::none);
1441}
1442
1443inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001444bool copy_file(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001445 return __copy_file(__from, __to, copy_options::none, &__ec);
1446}
1447
1448inline _LIBCPP_INLINE_VISIBILITY
1449bool copy_file(const path& __from, const path& __to, copy_options __opt) {
1450 return __copy_file(__from, __to, __opt);
1451}
1452
1453inline _LIBCPP_INLINE_VISIBILITY
1454bool copy_file(const path& __from, const path& __to,
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001455 copy_options __opt, error_code& __ec){
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001456 return __copy_file(__from, __to, __opt, &__ec);
1457}
1458
1459inline _LIBCPP_INLINE_VISIBILITY
1460void copy_symlink(const path& __existing, const path& __new) {
1461 __copy_symlink(__existing, __new);
1462}
1463
1464inline _LIBCPP_INLINE_VISIBILITY
1465void copy_symlink(const path& __ext, const path& __new, error_code& __ec) _NOEXCEPT {
1466 __copy_symlink(__ext, __new, &__ec);
1467}
1468
1469inline _LIBCPP_INLINE_VISIBILITY
1470bool create_directories(const path& __p) {
1471 return __create_directories(__p);
1472}
1473
1474inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001475bool create_directories(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001476 return __create_directories(__p, &__ec);
1477}
1478
1479inline _LIBCPP_INLINE_VISIBILITY
1480bool create_directory(const path& __p) {
1481 return __create_directory(__p);
1482}
1483
1484inline _LIBCPP_INLINE_VISIBILITY
1485bool create_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1486 return __create_directory(__p, &__ec);
1487}
1488
1489inline _LIBCPP_INLINE_VISIBILITY
1490bool create_directory(const path& __p, const path& __attrs) {
1491 return __create_directory(__p, __attrs);
1492}
1493
1494inline _LIBCPP_INLINE_VISIBILITY
1495bool create_directory(const path& __p, const path& __attrs, error_code& __ec) _NOEXCEPT {
1496 return __create_directory(__p, __attrs, &__ec);
1497}
1498
1499inline _LIBCPP_INLINE_VISIBILITY
1500void create_directory_symlink(const path& __to, const path& __new) {
1501 __create_directory_symlink(__to, __new);
1502}
1503
1504inline _LIBCPP_INLINE_VISIBILITY
1505void create_directory_symlink(const path& __to, const path& __new,
1506 error_code& __ec) _NOEXCEPT {
1507 __create_directory_symlink(__to, __new, &__ec);
1508}
1509
1510inline _LIBCPP_INLINE_VISIBILITY
1511void create_hard_link(const path& __to, const path& __new) {
1512 __create_hard_link(__to, __new);
1513}
1514
1515inline _LIBCPP_INLINE_VISIBILITY
1516void create_hard_link(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
1517 __create_hard_link(__to, __new, &__ec);
1518}
1519
1520inline _LIBCPP_INLINE_VISIBILITY
1521void create_symlink(const path& __to, const path& __new) {
1522 __create_symlink(__to, __new);
1523}
1524
1525inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1e34c762018-04-02 23:03:41 +00001526void create_symlink(const path& __to, const path& __new,
1527 error_code& __ec) _NOEXCEPT {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001528 return __create_symlink(__to, __new, &__ec);
1529}
1530
1531inline _LIBCPP_INLINE_VISIBILITY
1532bool status_known(file_status __s) _NOEXCEPT {
1533 return __s.type() != file_type::none;
1534}
1535
1536inline _LIBCPP_INLINE_VISIBILITY
1537bool exists(file_status __s) _NOEXCEPT {
1538 return status_known(__s) && __s.type() != file_type::not_found;
1539}
1540
1541inline _LIBCPP_INLINE_VISIBILITY
1542bool exists(const path& __p) {
1543 return exists(__status(__p));
1544}
1545
1546inline _LIBCPP_INLINE_VISIBILITY
1547bool exists(const path& __p, error_code& __ec) _NOEXCEPT {
Eric Fiselier756a6bd2016-06-21 22:11:16 +00001548 auto __s = __status(__p, &__ec);
1549 if (status_known(__s)) __ec.clear();
1550 return exists(__s);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001551}
1552
1553inline _LIBCPP_INLINE_VISIBILITY
1554bool equivalent(const path& __p1, const path& __p2) {
1555 return __equivalent(__p1, __p2);
1556}
1557
1558inline _LIBCPP_INLINE_VISIBILITY
1559bool equivalent(const path& __p1, const path& __p2, error_code& __ec) _NOEXCEPT {
1560 return __equivalent(__p1, __p2, &__ec);
1561}
1562
1563inline _LIBCPP_INLINE_VISIBILITY
1564uintmax_t file_size(const path& __p) {
1565 return __file_size(__p);
1566}
1567
1568inline _LIBCPP_INLINE_VISIBILITY
1569uintmax_t file_size(const path& __p, error_code& __ec) _NOEXCEPT {
1570 return __file_size(__p, &__ec);
1571}
1572
1573inline _LIBCPP_INLINE_VISIBILITY
1574uintmax_t hard_link_count(const path& __p) {
1575 return __hard_link_count(__p);
1576}
1577
1578inline _LIBCPP_INLINE_VISIBILITY
1579uintmax_t hard_link_count(const path& __p, error_code& __ec) _NOEXCEPT {
1580 return __hard_link_count(__p, &__ec);
1581}
1582
1583inline _LIBCPP_INLINE_VISIBILITY
1584bool is_block_file(file_status __s) _NOEXCEPT {
1585 return __s.type() == file_type::block;
1586}
1587
1588inline _LIBCPP_INLINE_VISIBILITY
1589bool is_block_file(const path& __p) {
1590 return is_block_file(__status(__p));
1591}
1592
1593inline _LIBCPP_INLINE_VISIBILITY
1594bool is_block_file(const path& __p, error_code& __ec) _NOEXCEPT {
1595 return is_block_file(__status(__p, &__ec));
1596}
1597
1598inline _LIBCPP_INLINE_VISIBILITY
1599bool is_character_file(file_status __s) _NOEXCEPT {
1600 return __s.type() == file_type::character;
1601}
1602
1603inline _LIBCPP_INLINE_VISIBILITY
1604bool is_character_file(const path& __p) {
1605 return is_character_file(__status(__p));
1606}
1607
1608inline _LIBCPP_INLINE_VISIBILITY
1609bool is_character_file(const path& __p, error_code& __ec) _NOEXCEPT {
1610 return is_character_file(__status(__p, &__ec));
1611}
1612
1613inline _LIBCPP_INLINE_VISIBILITY
1614bool is_directory(file_status __s) _NOEXCEPT {
1615 return __s.type() == file_type::directory;
1616}
1617
1618inline _LIBCPP_INLINE_VISIBILITY
1619bool is_directory(const path& __p) {
1620 return is_directory(__status(__p));
1621}
1622
1623inline _LIBCPP_INLINE_VISIBILITY
1624bool is_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1625 return is_directory(__status(__p, &__ec));
1626}
1627
1628inline _LIBCPP_INLINE_VISIBILITY
1629bool is_empty(const path& __p) {
1630 return __fs_is_empty(__p);
1631}
1632
1633inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001634bool is_empty(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001635 return __fs_is_empty(__p, &__ec);
1636}
1637
1638inline _LIBCPP_INLINE_VISIBILITY
1639bool is_fifo(file_status __s) _NOEXCEPT {
1640 return __s.type() == file_type::fifo;
1641}
1642inline _LIBCPP_INLINE_VISIBILITY
1643bool is_fifo(const path& __p) {
1644 return is_fifo(__status(__p));
1645}
1646
1647inline _LIBCPP_INLINE_VISIBILITY
1648bool is_fifo(const path& __p, error_code& __ec) _NOEXCEPT {
1649 return is_fifo(__status(__p, &__ec));
1650}
1651
1652inline _LIBCPP_INLINE_VISIBILITY
1653bool is_regular_file(file_status __s) _NOEXCEPT {
1654 return __s.type() == file_type::regular;
1655}
1656
1657inline _LIBCPP_INLINE_VISIBILITY
1658bool is_regular_file(const path& __p) {
1659 return is_regular_file(__status(__p));
1660}
1661
1662inline _LIBCPP_INLINE_VISIBILITY
1663bool is_regular_file(const path& __p, error_code& __ec) _NOEXCEPT {
1664 return is_regular_file(__status(__p, &__ec));
1665}
1666
1667inline _LIBCPP_INLINE_VISIBILITY
1668bool is_socket(file_status __s) _NOEXCEPT {
1669 return __s.type() == file_type::socket;
1670}
1671
1672inline _LIBCPP_INLINE_VISIBILITY
1673bool is_socket(const path& __p) {
1674 return is_socket(__status(__p));
1675}
1676
1677inline _LIBCPP_INLINE_VISIBILITY
1678bool is_socket(const path& __p, error_code& __ec) _NOEXCEPT {
1679 return is_socket(__status(__p, &__ec));
1680}
1681
1682inline _LIBCPP_INLINE_VISIBILITY
1683bool is_symlink(file_status __s) _NOEXCEPT {
1684 return __s.type() == file_type::symlink;
1685}
1686
1687inline _LIBCPP_INLINE_VISIBILITY
1688bool is_symlink(const path& __p) {
1689 return is_symlink(__symlink_status(__p));
1690}
1691
1692inline _LIBCPP_INLINE_VISIBILITY
1693bool is_symlink(const path& __p, error_code& __ec) _NOEXCEPT {
1694 return is_symlink(__symlink_status(__p, &__ec));
1695}
1696
1697inline _LIBCPP_INLINE_VISIBILITY
1698bool is_other(file_status __s) _NOEXCEPT {
1699 return exists(__s)
1700 && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s);
1701}
1702
1703inline _LIBCPP_INLINE_VISIBILITY
1704bool is_other(const path& __p) {
1705 return is_other(__status(__p));
1706}
1707
1708inline _LIBCPP_INLINE_VISIBILITY
1709bool is_other(const path& __p, error_code& __ec) _NOEXCEPT {
1710 return is_other(__status(__p, &__ec));
1711}
1712
1713inline _LIBCPP_INLINE_VISIBILITY
1714file_time_type last_write_time(const path& __p) {
1715 return __last_write_time(__p);
1716}
1717
1718inline _LIBCPP_INLINE_VISIBILITY
1719file_time_type last_write_time(const path& __p, error_code& __ec) _NOEXCEPT {
1720 return __last_write_time(__p, &__ec);
1721}
1722
1723inline _LIBCPP_INLINE_VISIBILITY
1724void last_write_time(const path& __p, file_time_type __t) {
1725 __last_write_time(__p, __t);
1726}
1727
1728inline _LIBCPP_INLINE_VISIBILITY
1729void last_write_time(const path& __p, file_time_type __t, error_code& __ec) _NOEXCEPT {
1730 __last_write_time(__p, __t, &__ec);
1731}
1732
1733inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf2c93732018-03-26 06:23:55 +00001734void permissions(const path& __p, perms __prms,
1735 perm_options __opts = perm_options::replace) {
1736 __permissions(__p, __prms, __opts);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001737}
1738
1739inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf2c93732018-03-26 06:23:55 +00001740void permissions(const path& __p, perms __prms, error_code& __ec) _NOEXCEPT {
1741 __permissions(__p, __prms, perm_options::replace, &__ec);
1742}
1743
1744inline _LIBCPP_INLINE_VISIBILITY
1745void permissions(const path& __p, perms __prms, perm_options __opts,
1746 error_code& __ec) {
1747 __permissions(__p, __prms, __opts, &__ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001748}
1749
1750inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1e34c762018-04-02 23:03:41 +00001751path proximate(const path& __p, const path& __base, error_code& __ec) {
1752 path __tmp = __weakly_canonical(__p, &__ec);
1753 if (__ec)
1754 return {};
1755 path __tmp_base = __weakly_canonical(__base, &__ec);
1756 if (__ec)
1757 return {};
1758 return __tmp.lexically_proximate(__tmp_base);
1759}
1760
1761inline _LIBCPP_INLINE_VISIBILITY
1762path proximate(const path& __p, error_code& __ec) {
1763 return proximate(__p, current_path(), __ec);
1764}
1765
1766inline _LIBCPP_INLINE_VISIBILITY
1767path proximate(const path& __p, const path& __base = current_path()) {
1768 return __weakly_canonical(__p).lexically_proximate(__weakly_canonical(__base));
1769}
1770
1771inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001772path read_symlink(const path& __p) {
1773 return __read_symlink(__p);
1774}
1775
1776inline _LIBCPP_INLINE_VISIBILITY
1777path read_symlink(const path& __p, error_code& __ec) {
1778 return __read_symlink(__p, &__ec);
1779}
1780
Eric Fiselier1e34c762018-04-02 23:03:41 +00001781
1782inline _LIBCPP_INLINE_VISIBILITY
1783path relative(const path& __p, const path& __base, error_code& __ec) {
1784 path __tmp = __weakly_canonical(__p, &__ec);
1785 if (__ec)
1786 return path();
1787 path __tmpbase = __weakly_canonical(__base, &__ec);
1788 if (__ec)
1789 return path();
1790 return __tmp.lexically_relative(__tmpbase);
1791}
1792
1793inline _LIBCPP_INLINE_VISIBILITY
1794path relative(const path& __p, error_code& __ec) {
1795 return relative(__p, current_path(), __ec);
1796}
1797
1798inline _LIBCPP_INLINE_VISIBILITY
1799path relative(const path& __p, const path& __base=current_path()) {
1800 return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
1801}
1802
1803
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001804inline _LIBCPP_INLINE_VISIBILITY
1805bool remove(const path& __p) {
1806 return __remove(__p);
1807}
1808
1809inline _LIBCPP_INLINE_VISIBILITY
1810bool remove(const path& __p, error_code& __ec) _NOEXCEPT {
1811 return __remove(__p, &__ec);
1812}
1813
1814inline _LIBCPP_INLINE_VISIBILITY
1815uintmax_t remove_all(const path& __p) {
1816 return __remove_all(__p);
1817}
1818
1819inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001820uintmax_t remove_all(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001821 return __remove_all(__p, &__ec);
1822}
1823
1824inline _LIBCPP_INLINE_VISIBILITY
1825void rename(const path& __from, const path& __to) {
1826 return __rename(__from, __to);
1827}
1828
1829inline _LIBCPP_INLINE_VISIBILITY
1830void rename(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
1831 return __rename(__from, __to, &__ec);
1832}
1833
1834inline _LIBCPP_INLINE_VISIBILITY
1835void resize_file(const path& __p, uintmax_t __ns) {
1836 return __resize_file(__p, __ns);
1837}
1838
1839inline _LIBCPP_INLINE_VISIBILITY
1840void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) _NOEXCEPT {
1841 return __resize_file(__p, __ns, &__ec);
1842}
1843
1844inline _LIBCPP_INLINE_VISIBILITY
1845space_info space(const path& __p) {
1846 return __space(__p);
1847}
1848
1849inline _LIBCPP_INLINE_VISIBILITY
1850space_info space(const path& __p, error_code& __ec) _NOEXCEPT {
1851 return __space(__p, &__ec);
1852}
1853
1854inline _LIBCPP_INLINE_VISIBILITY
1855file_status status(const path& __p) {
1856 return __status(__p);
1857}
1858
1859inline _LIBCPP_INLINE_VISIBILITY
1860file_status status(const path& __p, error_code& __ec) _NOEXCEPT {
1861 return __status(__p, &__ec);
1862}
1863
1864inline _LIBCPP_INLINE_VISIBILITY
1865file_status symlink_status(const path& __p) {
1866 return __symlink_status(__p);
1867}
1868
1869inline _LIBCPP_INLINE_VISIBILITY
1870file_status symlink_status(const path& __p, error_code& __ec) _NOEXCEPT {
1871 return __symlink_status(__p, &__ec);
1872}
1873
1874inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001875path temp_directory_path() {
1876 return __temp_directory_path();
1877}
1878
1879inline _LIBCPP_INLINE_VISIBILITY
1880path temp_directory_path(error_code& __ec) {
1881 return __temp_directory_path(&__ec);
1882}
1883
Eric Fiselier1e34c762018-04-02 23:03:41 +00001884inline _LIBCPP_INLINE_VISIBILITY
1885path weakly_canonical(path const& __p) {
1886 return __weakly_canonical(__p);
1887}
1888
1889inline _LIBCPP_INLINE_VISIBILITY
1890path weakly_canonical(path const& __p, error_code& __ec) {
1891 return __weakly_canonical(__p, &__ec);
1892}
1893
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001894
1895class directory_entry
1896{
1897 typedef _VSTD_FS::path _Path;
1898
1899public:
1900 // constructors and destructors
1901 directory_entry() _NOEXCEPT = default;
1902 directory_entry(directory_entry const&) = default;
1903 directory_entry(directory_entry&&) _NOEXCEPT = default;
1904
1905 _LIBCPP_INLINE_VISIBILITY
1906 explicit directory_entry(_Path const& __p) : __p_(__p) {}
1907
1908 ~directory_entry() {}
1909
1910 directory_entry& operator=(directory_entry const&) = default;
1911 directory_entry& operator=(directory_entry&&) _NOEXCEPT = default;
1912
1913 _LIBCPP_INLINE_VISIBILITY
1914 void assign(_Path const& __p) {
1915 __p_ = __p;
1916 }
1917
1918 _LIBCPP_INLINE_VISIBILITY
1919 void replace_filename(_Path const& __p) {
1920 __p_ = __p_.parent_path() / __p;
1921 }
1922
1923 _LIBCPP_INLINE_VISIBILITY
1924 _Path const& path() const _NOEXCEPT {
1925 return __p_;
1926 }
1927
1928 _LIBCPP_INLINE_VISIBILITY
1929 operator const _Path&() const _NOEXCEPT {
1930 return __p_;
1931 }
1932
1933 _LIBCPP_INLINE_VISIBILITY
1934 file_status status() const {
1935 return _VSTD_FS::status(__p_);
1936 }
1937
1938 _LIBCPP_INLINE_VISIBILITY
1939 file_status status(error_code& __ec) const _NOEXCEPT {
1940 return _VSTD_FS::status(__p_, __ec);
1941 }
1942
1943 _LIBCPP_INLINE_VISIBILITY
1944 file_status symlink_status() const {
1945 return _VSTD_FS::symlink_status(__p_);
1946 }
1947
1948 _LIBCPP_INLINE_VISIBILITY
1949 file_status symlink_status(error_code& __ec) const _NOEXCEPT {
1950 return _VSTD_FS::symlink_status(__p_, __ec);
1951 }
1952
1953 _LIBCPP_INLINE_VISIBILITY
1954 bool operator< (directory_entry const& __rhs) const _NOEXCEPT {
1955 return __p_ < __rhs.__p_;
1956 }
1957
1958 _LIBCPP_INLINE_VISIBILITY
1959 bool operator==(directory_entry const& __rhs) const _NOEXCEPT {
1960 return __p_ == __rhs.__p_;
1961 }
1962
1963 _LIBCPP_INLINE_VISIBILITY
1964 bool operator!=(directory_entry const& __rhs) const _NOEXCEPT {
1965 return __p_ != __rhs.__p_;
1966 }
1967
1968 _LIBCPP_INLINE_VISIBILITY
1969 bool operator<=(directory_entry const& __rhs) const _NOEXCEPT {
1970 return __p_ <= __rhs.__p_;
1971 }
1972
1973 _LIBCPP_INLINE_VISIBILITY
1974 bool operator> (directory_entry const& __rhs) const _NOEXCEPT {
1975 return __p_ > __rhs.__p_;
1976 }
1977
1978 _LIBCPP_INLINE_VISIBILITY
1979 bool operator>=(directory_entry const& __rhs) const _NOEXCEPT {
1980 return __p_ >= __rhs.__p_;
1981 }
1982private:
1983 _Path __p_;
1984};
1985
1986
1987class directory_iterator;
1988class recursive_directory_iterator;
1989class __dir_stream;
1990
1991class __dir_element_proxy {
1992public:
1993
1994 inline _LIBCPP_INLINE_VISIBILITY
1995 directory_entry operator*() { return _VSTD::move(__elem_); }
1996
1997private:
1998 friend class directory_iterator;
1999 friend class recursive_directory_iterator;
2000 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
2001 __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {}
2002 directory_entry __elem_;
2003};
2004
2005class directory_iterator
2006{
2007public:
2008 typedef directory_entry value_type;
2009 typedef ptrdiff_t difference_type;
2010 typedef value_type const* pointer;
2011 typedef value_type const& reference;
2012 typedef input_iterator_tag iterator_category;
2013
2014public:
2015 //ctor & dtor
2016 directory_iterator() _NOEXCEPT
2017 { }
2018
2019 explicit directory_iterator(const path& __p)
2020 : directory_iterator(__p, nullptr)
2021 { }
2022
2023 directory_iterator(const path& __p, directory_options __opts)
2024 : directory_iterator(__p, nullptr, __opts)
2025 { }
2026
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002027 directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002028 : directory_iterator(__p, &__ec)
2029 { }
2030
2031 directory_iterator(const path& __p, directory_options __opts,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002032 error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002033 : directory_iterator(__p, &__ec, __opts)
2034 { }
2035
2036 directory_iterator(const directory_iterator&) = default;
2037 directory_iterator(directory_iterator&&) = default;
2038 directory_iterator& operator=(const directory_iterator&) = default;
2039
2040 directory_iterator& operator=(directory_iterator&& __o) _NOEXCEPT {
2041 // non-default implementation provided to support self-move assign.
2042 if (this != &__o) {
2043 __imp_ = _VSTD::move(__o.__imp_);
2044 }
2045 return *this;
2046 }
2047
2048 ~directory_iterator() = default;
2049
2050 const directory_entry& operator*() const {
2051 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002052 return __dereference();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002053 }
2054
2055 const directory_entry* operator->() const
2056 { return &**this; }
2057
2058 directory_iterator& operator++()
2059 { return __increment(); }
2060
2061 __dir_element_proxy operator++(int) {
2062 __dir_element_proxy __p(**this);
2063 __increment();
2064 return __p;
2065 }
2066
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002067 directory_iterator& increment(error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002068 { return __increment(&__ec); }
2069
2070private:
Eric Fiselier03f7d102016-09-16 00:07:16 +00002071 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002072 friend bool operator==(const directory_iterator& __lhs,
2073 const directory_iterator& __rhs) _NOEXCEPT;
2074
2075 // construct the dir_stream
2076 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002077 directory_iterator(const path&, error_code *,
2078 directory_options = directory_options::none);
2079
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002080 _LIBCPP_FUNC_VIS
2081 directory_iterator& __increment(error_code * __ec = nullptr);
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002082
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002083 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002084 const directory_entry& __dereference() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002085
2086private:
2087 shared_ptr<__dir_stream> __imp_;
2088};
2089
2090
2091inline _LIBCPP_INLINE_VISIBILITY
2092bool operator==(const directory_iterator& __lhs,
2093 const directory_iterator& __rhs) _NOEXCEPT {
2094 return __lhs.__imp_ == __rhs.__imp_;
2095}
2096
2097inline _LIBCPP_INLINE_VISIBILITY
2098bool operator!=(const directory_iterator& __lhs,
2099 const directory_iterator& __rhs) _NOEXCEPT {
2100 return !(__lhs == __rhs);
2101}
2102
2103// enable directory_iterator range-based for statements
2104inline _LIBCPP_INLINE_VISIBILITY
2105directory_iterator begin(directory_iterator __iter) _NOEXCEPT {
2106 return __iter;
2107}
2108
2109inline _LIBCPP_INLINE_VISIBILITY
2110directory_iterator end(const directory_iterator&) _NOEXCEPT {
2111 return directory_iterator();
2112}
2113
2114class recursive_directory_iterator {
2115public:
2116 using value_type = directory_entry;
2117 using difference_type = std::ptrdiff_t;
2118 using pointer = directory_entry const *;
2119 using reference = directory_entry const &;
2120 using iterator_category = std::input_iterator_tag;
2121
2122public:
2123 // constructors and destructor
2124 _LIBCPP_INLINE_VISIBILITY
2125 recursive_directory_iterator() _NOEXCEPT
2126 : __rec_(false)
2127 {}
2128
2129 _LIBCPP_INLINE_VISIBILITY
2130 explicit recursive_directory_iterator(const path& __p,
2131 directory_options __xoptions = directory_options::none)
2132 : recursive_directory_iterator(__p, __xoptions, nullptr)
2133 { }
2134
2135 _LIBCPP_INLINE_VISIBILITY
2136 recursive_directory_iterator(const path& __p,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002137 directory_options __xoptions, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002138 : recursive_directory_iterator(__p, __xoptions, &__ec)
2139 { }
2140
2141 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002142 recursive_directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002143 : recursive_directory_iterator(__p, directory_options::none, &__ec)
2144 { }
2145
2146 recursive_directory_iterator(const recursive_directory_iterator&) = default;
2147 recursive_directory_iterator(recursive_directory_iterator&&) = default;
2148
2149 recursive_directory_iterator &
2150 operator=(const recursive_directory_iterator&) = default;
2151
2152 _LIBCPP_INLINE_VISIBILITY
2153 recursive_directory_iterator &
2154 operator=(recursive_directory_iterator&& __o) noexcept {
2155 // non-default implementation provided to support self-move assign.
2156 if (this != &__o) {
2157 __imp_ = _VSTD::move(__o.__imp_);
2158 __rec_ = __o.__rec_;
2159 }
2160 return *this;
2161 }
2162
2163 ~recursive_directory_iterator() = default;
2164
2165 _LIBCPP_INLINE_VISIBILITY
2166 const directory_entry& operator*() const
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002167 { return __dereference(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002168
2169 _LIBCPP_INLINE_VISIBILITY
2170 const directory_entry* operator->() const
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002171 { return &__dereference(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002172
2173 recursive_directory_iterator& operator++()
2174 { return __increment(); }
2175
2176 _LIBCPP_INLINE_VISIBILITY
2177 __dir_element_proxy operator++(int) {
2178 __dir_element_proxy __p(**this);
2179 __increment();
2180 return __p;
2181 }
2182
2183 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002184 recursive_directory_iterator& increment(error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002185 { return __increment(&__ec); }
2186
2187 _LIBCPP_FUNC_VIS directory_options options() const;
2188 _LIBCPP_FUNC_VIS int depth() const;
2189
2190 _LIBCPP_INLINE_VISIBILITY
2191 void pop() { __pop(); }
2192
2193 _LIBCPP_INLINE_VISIBILITY
2194 void pop(error_code& __ec)
2195 { __pop(&__ec); }
2196
2197 _LIBCPP_INLINE_VISIBILITY
2198 bool recursion_pending() const
2199 { return __rec_; }
2200
2201 _LIBCPP_INLINE_VISIBILITY
2202 void disable_recursion_pending()
2203 { __rec_ = false; }
2204
2205private:
2206 recursive_directory_iterator(const path& __p, directory_options __opt,
2207 error_code *__ec);
2208
2209 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002210 const directory_entry& __dereference() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002211
2212 _LIBCPP_FUNC_VIS
2213 bool __try_recursion(error_code* __ec);
2214
2215 _LIBCPP_FUNC_VIS
2216 void __advance(error_code* __ec=nullptr);
2217
2218 _LIBCPP_FUNC_VIS
2219 recursive_directory_iterator& __increment(error_code *__ec=nullptr);
2220
2221 _LIBCPP_FUNC_VIS
2222 void __pop(error_code* __ec=nullptr);
2223
Eric Fiselier03f7d102016-09-16 00:07:16 +00002224 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002225 friend bool operator==(const recursive_directory_iterator&,
2226 const recursive_directory_iterator&) _NOEXCEPT;
2227
2228 struct __shared_imp;
2229 shared_ptr<__shared_imp> __imp_;
2230 bool __rec_;
2231}; // class recursive_directory_iterator
2232
2233
Eric Fiselier03f7d102016-09-16 00:07:16 +00002234inline _LIBCPP_INLINE_VISIBILITY
2235bool operator==(const recursive_directory_iterator& __lhs,
2236 const recursive_directory_iterator& __rhs) _NOEXCEPT
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002237{
2238 return __lhs.__imp_ == __rhs.__imp_;
2239}
2240
2241_LIBCPP_INLINE_VISIBILITY
2242inline bool operator!=(const recursive_directory_iterator& __lhs,
2243 const recursive_directory_iterator& __rhs) _NOEXCEPT
2244{
2245 return !(__lhs == __rhs);
2246}
2247// enable recursive_directory_iterator range-based for statements
2248inline _LIBCPP_INLINE_VISIBILITY
2249recursive_directory_iterator begin(recursive_directory_iterator __iter) _NOEXCEPT {
2250 return __iter;
2251}
2252
2253inline _LIBCPP_INLINE_VISIBILITY
2254recursive_directory_iterator end(const recursive_directory_iterator&) _NOEXCEPT {
2255 return recursive_directory_iterator();
2256}
2257
2258_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
2259
2260#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM