blob: 0075ad2b084a736ae57fa21b84d700e8a4992267 [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
31 template <class charT, class traits>
32 basic_ostream<charT, traits>&
33 operator<<(basic_ostream<charT, traits>& os, const path& p);
34
35 template <class charT, class traits>
36 basic_istream<charT, traits>&
37 operator>>(basic_istream<charT, traits>& is, path& p);
38
39 template <class Source>
40 path u8path(const Source& source);
41 template <class InputIterator>
42 path u8path(InputIterator first, InputIterator last);
43
44 class filesystem_error;
45 class directory_entry;
46
47 class directory_iterator;
48
49 // enable directory_iterator range-based for statements
50 directory_iterator begin(directory_iterator iter) noexcept;
51 directory_iterator end(const directory_iterator&) noexcept;
52
53 class recursive_directory_iterator;
54
55 // enable recursive_directory_iterator range-based for statements
56 recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
57 recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
58
59 class file_status;
60
61 struct space_info
62 {
63 uintmax_t capacity;
64 uintmax_t free;
65 uintmax_t available;
66 };
67
68 enum class file_type;
69 enum class perms;
70 enum class copy_options;
71 enum class directory_options;
72
73 typedef chrono::time_point<trivial-clock> file_time_type;
74
75 // operational functions
76
77 path absolute(const path& p, const path& base=current_path());
78
79 path canonical(const path& p, const path& base = current_path());
80 path canonical(const path& p, error_code& ec);
81 path canonical(const path& p, const path& base, error_code& ec);
82
83 void copy(const path& from, const path& to);
84 void copy(const path& from, const path& to, error_code& ec) _NOEXCEPT;
85 void copy(const path& from, const path& to, copy_options options);
86 void copy(const path& from, const path& to, copy_options options,
87 error_code& ec) _NOEXCEPT;
88
89 bool copy_file(const path& from, const path& to);
90 bool copy_file(const path& from, const path& to, error_code& ec) _NOEXCEPT;
91 bool copy_file(const path& from, const path& to, copy_options option);
92 bool copy_file(const path& from, const path& to, copy_options option,
93 error_code& ec) _NOEXCEPT;
94
95 void copy_symlink(const path& existing_symlink, const path& new_symlink);
96 void copy_symlink(const path& existing_symlink, const path& new_symlink,
97 error_code& ec) _NOEXCEPT;
98
99 bool create_directories(const path& p);
100 bool create_directories(const path& p, error_code& ec) _NOEXCEPT;
101
102 bool create_directory(const path& p);
103 bool create_directory(const path& p, error_code& ec) _NOEXCEPT;
104
105 bool create_directory(const path& p, const path& attributes);
106 bool create_directory(const path& p, const path& attributes,
107 error_code& ec) _NOEXCEPT;
108
109 void create_directory_symlink(const path& to, const path& new_symlink);
110 void create_directory_symlink(const path& to, const path& new_symlink,
111 error_code& ec) _NOEXCEPT;
112
113 void create_hard_link(const path& to, const path& new_hard_link);
114 void create_hard_link(const path& to, const path& new_hard_link,
115 error_code& ec) _NOEXCEPT;
116
117 void create_symlink(const path& to, const path& new_symlink);
118 void create_symlink(const path& to, const path& new_symlink,
119 error_code& ec) _NOEXCEPT;
120
121 path current_path();
122 path current_path(error_code& ec);
123 void current_path(const path& p);
124 void current_path(const path& p, error_code& ec) _NOEXCEPT;
125
126 bool exists(file_status s) _NOEXCEPT;
127 bool exists(const path& p);
128 bool exists(const path& p, error_code& ec) _NOEXCEPT;
129
130 bool equivalent(const path& p1, const path& p2);
131 bool equivalent(const path& p1, const path& p2, error_code& ec) _NOEXCEPT;
132
133 uintmax_t file_size(const path& p);
134 uintmax_t file_size(const path& p, error_code& ec) _NOEXCEPT;
135
136 uintmax_t hard_link_count(const path& p);
137 uintmax_t hard_link_count(const path& p, error_code& ec) _NOEXCEPT;
138
139 bool is_block_file(file_status s) _NOEXCEPT;
140 bool is_block_file(const path& p);
141 bool is_block_file(const path& p, error_code& ec) _NOEXCEPT;
142
143 bool is_character_file(file_status s) _NOEXCEPT;
144 bool is_character_file(const path& p);
145 bool is_character_file(const path& p, error_code& ec) _NOEXCEPT;
146
147 bool is_directory(file_status s) _NOEXCEPT;
148 bool is_directory(const path& p);
149 bool is_directory(const path& p, error_code& ec) _NOEXCEPT;
150
151 bool is_empty(const path& p);
152 bool is_empty(const path& p, error_code& ec) _NOEXCEPT;
153
154 bool is_fifo(file_status s) _NOEXCEPT;
155 bool is_fifo(const path& p);
156 bool is_fifo(const path& p, error_code& ec) _NOEXCEPT;
157
158 bool is_other(file_status s) _NOEXCEPT;
159 bool is_other(const path& p);
160 bool is_other(const path& p, error_code& ec) _NOEXCEPT;
161
162 bool is_regular_file(file_status s) _NOEXCEPT;
163 bool is_regular_file(const path& p);
164 bool is_regular_file(const path& p, error_code& ec) _NOEXCEPT;
165
166 bool is_socket(file_status s) _NOEXCEPT;
167 bool is_socket(const path& p);
168 bool is_socket(const path& p, error_code& ec) _NOEXCEPT;
169
170 bool is_symlink(file_status s) _NOEXCEPT;
171 bool is_symlink(const path& p);
172 bool is_symlink(const path& p, error_code& ec) _NOEXCEPT;
173
174 file_time_type last_write_time(const path& p);
175 file_time_type last_write_time(const path& p, error_code& ec) _NOEXCEPT;
176 void last_write_time(const path& p, file_time_type new_time);
177 void last_write_time(const path& p, file_time_type new_time,
178 error_code& ec) _NOEXCEPT;
179
180 void permissions(const path& p, perms prms);
181 void permissions(const path& p, perms prms, error_code& ec) _NOEXCEPT;
182
183 path read_symlink(const path& p);
184 path read_symlink(const path& p, error_code& ec);
185
186 bool remove(const path& p);
187 bool remove(const path& p, error_code& ec) _NOEXCEPT;
188
189 uintmax_t remove_all(const path& p);
190 uintmax_t remove_all(const path& p, error_code& ec) _NOEXCEPT;
191
192 void rename(const path& from, const path& to);
193 void rename(const path& from, const path& to, error_code& ec) _NOEXCEPT;
194
195 void resize_file(const path& p, uintmax_t size);
196 void resize_file(const path& p, uintmax_t size, error_code& ec) _NOEXCEPT;
197
198 space_info space(const path& p);
199 space_info space(const path& p, error_code& ec) _NOEXCEPT;
200
201 file_status status(const path& p);
202 file_status status(const path& p, error_code& ec) _NOEXCEPT;
203
204 bool status_known(file_status s) _NOEXCEPT;
205
206 file_status symlink_status(const path& p);
207 file_status symlink_status(const path& p, error_code& ec) _NOEXCEPT;
208
209 path system_complete(const path& p);
210 path system_complete(const path& p, error_code& ec);
211
212 path temp_directory_path();
213 path temp_directory_path(error_code& ec);
214
215} } } } // namespaces std::experimental::filesystem::v1
216
217*/
218
219#include <experimental/__config>
220#include <cstddef>
221#include <chrono>
222#include <iterator>
223#include <iosfwd>
224#include <locale>
225#include <memory>
226#include <stack>
227#include <string>
228#include <system_error>
229#include <utility>
230#include <iomanip> // for quoted
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000231#include <string_view>
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000232
233#include <__debug>
234
235#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
236#pragma GCC system_header
237#endif
238
239#define __cpp_lib_experimental_filesystem 201406
240
241_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM
242
243typedef chrono::time_point<std::chrono::system_clock> file_time_type;
244
245struct _LIBCPP_TYPE_VIS space_info
246{
247 uintmax_t capacity;
248 uintmax_t free;
249 uintmax_t available;
250};
251
252enum class _LIBCPP_TYPE_VIS file_type : signed char
253{
254 none = 0,
255 not_found = -1,
256 regular = 1,
257 directory = 2,
258 symlink = 3,
259 block = 4,
260 character = 5,
261 fifo = 6,
262 socket = 7,
263 unknown = 8
264};
265
266enum class _LIBCPP_TYPE_VIS perms : unsigned
267{
268 none = 0,
269
270 owner_read = 0400,
271 owner_write = 0200,
272 owner_exec = 0100,
273 owner_all = 0700,
274
275 group_read = 040,
276 group_write = 020,
277 group_exec = 010,
278 group_all = 070,
279
280 others_read = 04,
281 others_write = 02,
282 others_exec = 01,
283 others_all = 07,
284
285 all = 0777,
286
287 set_uid = 04000,
288 set_gid = 02000,
289 sticky_bit = 01000,
290 mask = 07777,
291 unknown = 0xFFFF,
292
293 add_perms = 0x10000,
294 remove_perms = 0x20000,
Eric Fiselier7c96ddb2016-06-21 22:42:42 +0000295 symlink_nofollow = 0x40000
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000296};
297
298_LIBCPP_INLINE_VISIBILITY
299inline _LIBCPP_CONSTEXPR perms operator&(perms _LHS, perms _RHS)
300{ return static_cast<perms>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }
301
302_LIBCPP_INLINE_VISIBILITY
303inline _LIBCPP_CONSTEXPR perms operator|(perms _LHS, perms _RHS)
304{ return static_cast<perms>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }
305
306_LIBCPP_INLINE_VISIBILITY
307inline _LIBCPP_CONSTEXPR perms operator^(perms _LHS, perms _RHS)
308{ return static_cast<perms>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }
309
310_LIBCPP_INLINE_VISIBILITY
311inline _LIBCPP_CONSTEXPR perms operator~(perms _LHS)
312{ return static_cast<perms>(~static_cast<unsigned>(_LHS)); }
313
314_LIBCPP_INLINE_VISIBILITY
315inline perms& operator&=(perms& _LHS, perms _RHS)
316{ return _LHS = _LHS & _RHS; }
317
318_LIBCPP_INLINE_VISIBILITY
319inline perms& operator|=(perms& _LHS, perms _RHS)
320{ return _LHS = _LHS | _RHS; }
321
322_LIBCPP_INLINE_VISIBILITY
323inline perms& operator^=(perms& _LHS, perms _RHS)
324{ return _LHS = _LHS ^ _RHS; }
325
326enum class _LIBCPP_TYPE_VIS copy_options : unsigned short
327{
328 none = 0,
329 skip_existing = 1,
330 overwrite_existing = 2,
331 update_existing = 4,
332 recursive = 8,
333 copy_symlinks = 16,
334 skip_symlinks = 32,
335 directories_only = 64,
336 create_symlinks = 128,
337 create_hard_links = 256,
338 __in_recursive_copy = 512,
339};
340
341_LIBCPP_INLINE_VISIBILITY
342inline _LIBCPP_CONSTEXPR copy_options operator&(copy_options _LHS, copy_options _RHS)
343{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) & static_cast<unsigned short>(_RHS)); }
344
345_LIBCPP_INLINE_VISIBILITY
346inline _LIBCPP_CONSTEXPR copy_options operator|(copy_options _LHS, copy_options _RHS)
347{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) | static_cast<unsigned short>(_RHS)); }
348
349_LIBCPP_INLINE_VISIBILITY
350inline _LIBCPP_CONSTEXPR copy_options operator^(copy_options _LHS, copy_options _RHS)
351{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^ static_cast<unsigned short>(_RHS)); }
352
353_LIBCPP_INLINE_VISIBILITY
354inline _LIBCPP_CONSTEXPR copy_options operator~(copy_options _LHS)
355{ return static_cast<copy_options>(~static_cast<unsigned short>(_LHS)); }
356
357_LIBCPP_INLINE_VISIBILITY
358inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS)
359{ return _LHS = _LHS & _RHS; }
360
361_LIBCPP_INLINE_VISIBILITY
362inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS)
363{ return _LHS = _LHS | _RHS; }
364
365_LIBCPP_INLINE_VISIBILITY
366inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS)
367{ return _LHS = _LHS ^ _RHS; }
368
369
370enum class directory_options : unsigned char
371{
372 none = 0,
373 follow_directory_symlink = 1,
374 skip_permission_denied = 2
375};
376
377_LIBCPP_INLINE_VISIBILITY
378inline _LIBCPP_CONSTEXPR directory_options operator&(directory_options _LHS, directory_options _RHS)
379{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) & static_cast<unsigned char>(_RHS)); }
380
381_LIBCPP_INLINE_VISIBILITY
382inline _LIBCPP_CONSTEXPR directory_options operator|(directory_options _LHS, directory_options _RHS)
383{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) | static_cast<unsigned char>(_RHS)); }
384
385_LIBCPP_INLINE_VISIBILITY
386inline _LIBCPP_CONSTEXPR directory_options operator^(directory_options _LHS, directory_options _RHS)
387{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^ static_cast<unsigned char>(_RHS)); }
388
389_LIBCPP_INLINE_VISIBILITY
390inline _LIBCPP_CONSTEXPR directory_options operator~(directory_options _LHS)
391{ return static_cast<directory_options>(~static_cast<unsigned char>(_LHS)); }
392
393_LIBCPP_INLINE_VISIBILITY
394inline directory_options& operator&=(directory_options& _LHS, directory_options _RHS)
395{ return _LHS = _LHS & _RHS; }
396
397_LIBCPP_INLINE_VISIBILITY
398inline directory_options& operator|=(directory_options& _LHS, directory_options _RHS)
399{ return _LHS = _LHS | _RHS; }
400
401_LIBCPP_INLINE_VISIBILITY
402inline directory_options& operator^=(directory_options& _LHS, directory_options _RHS)
403{ return _LHS = _LHS ^ _RHS; }
404
405
406class _LIBCPP_TYPE_VIS file_status
407{
408public:
409 // constructors
410 _LIBCPP_INLINE_VISIBILITY
411 explicit file_status(file_type __ft = file_type::none,
412 perms __prms = perms::unknown) _NOEXCEPT
413 : __ft_(__ft), __prms_(__prms)
414 {}
415
416 file_status(const file_status&) _NOEXCEPT = default;
417 file_status(file_status&&) _NOEXCEPT = default;
418
419 _LIBCPP_INLINE_VISIBILITY
420 ~file_status() {}
421
422 file_status& operator=(const file_status&) _NOEXCEPT = default;
423 file_status& operator=(file_status&&) _NOEXCEPT = default;
424
425 // observers
426 _LIBCPP_ALWAYS_INLINE
427 file_type type() const _NOEXCEPT {
428 return __ft_;
429 }
430
431 _LIBCPP_ALWAYS_INLINE
432 perms permissions() const _NOEXCEPT {
433 return __prms_;
434 }
435
436 // modifiers
437 _LIBCPP_ALWAYS_INLINE
438 void type(file_type __ft) _NOEXCEPT {
439 __ft_ = __ft;
440 }
441
442 _LIBCPP_ALWAYS_INLINE
443 void permissions(perms __p) _NOEXCEPT {
444 __prms_ = __p;
445 }
446private:
447 file_type __ft_;
448 perms __prms_;
449};
450
451class _LIBCPP_TYPE_VIS directory_entry;
452
453template <class _Tp> struct __can_convert_char {
454 static const bool value = false;
455};
456template <> struct __can_convert_char<char> {
457 static const bool value = true;
458 using __char_type = char;
459};
460template <> struct __can_convert_char<wchar_t> {
461 static const bool value = true;
462 using __char_type = wchar_t;
463};
464template <> struct __can_convert_char<char16_t> {
465 static const bool value = true;
466 using __char_type = char16_t;
467};
468template <> struct __can_convert_char<char32_t> {
469 static const bool value = true;
470 using __char_type = char32_t;
471};
472
473template <class _ECharT>
474typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
475__is_separator(_ECharT __e) {
476 return __e == _ECharT('/');
477};
478
479struct _NullSentinal {};
480
481template <class _Tp>
482using _Void = void;
483
484template <class _Tp, class = void>
485struct __is_pathable_string : public false_type {};
486
487template <class _ECharT, class _Traits, class _Alloc>
488struct __is_pathable_string<basic_string<_ECharT, _Traits, _Alloc>,
489 _Void<typename __can_convert_char<_ECharT>::__char_type>>
490: public __can_convert_char<_ECharT>
491{
492 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
493 using _Base = __can_convert_char<_ECharT>;
494 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
495 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
496 static _ECharT __first_or_null(_Str const& __s) {
497 return __s.empty() ? _ECharT{} : __s[0];
498 }
499};
500
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000501
502template <class _ECharT, class _Traits>
503struct __is_pathable_string<basic_string_view<_ECharT, _Traits>,
504 _Void<typename __can_convert_char<_ECharT>::__char_type>>
505: public __can_convert_char<_ECharT>
506{
507 using _Str = basic_string_view<_ECharT, _Traits>;
508 using _Base = __can_convert_char<_ECharT>;
509 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
510 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
511 static _ECharT __first_or_null(_Str const& __s) {
512 return __s.empty() ? _ECharT{} : __s[0];
513 }
514};
515
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000516template <class _Source,
517 class _DS = typename decay<_Source>::type,
518 class _UnqualPtrType = typename remove_const<
519 typename remove_pointer<_DS>::type>::type,
520 bool _IsCharPtr = is_pointer<_DS>::value &&
521 __can_convert_char<_UnqualPtrType>::value
522 >
523struct __is_pathable_char_array : false_type {};
524
525template <class _Source, class _ECharT, class _UPtr>
526struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
527 : __can_convert_char<typename remove_const<_ECharT>::type>
528{
529 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
530
531 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
532 static _ECharT const* __range_end(const _ECharT* __b)
533 {
534 using _Iter = const _ECharT*;
535 const _ECharT __sentinal = _ECharT{};
536 _Iter __e = __b;
537 for (; *__e != __sentinal; ++__e)
538 ;
539 return __e;
540 }
541
542 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
543};
544
545template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value, class = void>
546struct __is_pathable_iter : false_type {};
547
548template <class _Iter>
549struct __is_pathable_iter<_Iter, true,
550 _Void<typename __can_convert_char<typename iterator_traits<_Iter>::value_type>::__char_type>>
551 : __can_convert_char<typename iterator_traits<_Iter>::value_type>
552{
553 using _ECharT = typename iterator_traits<_Iter>::value_type;
554 using _Base = __can_convert_char<_ECharT>;
555
556 static _Iter __range_begin(_Iter __b) { return __b; }
557 static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; }
558
559 static _ECharT __first_or_null(_Iter __b) { return *__b; }
560};
561
562template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
563 bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
564 bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value
565 >
566struct __is_pathable : false_type {
567 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
568};
569
570template <class _Tp>
571struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
572
573
574template <class _Tp>
575struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {};
576
577
578template <class _Tp>
579struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
580
581
582template <class _ECharT>
583struct _PathCVT {
584 static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible");
585
586 typedef __narrow_to_utf8<sizeof(_ECharT)*__CHAR_BIT__> _Narrower;
587
588 static void __append_range(string& __dest, _ECharT const* __b, _ECharT const* __e) {
589 _Narrower()(back_inserter(__dest), __b, __e);
590 }
591
592 template <class _Iter>
593 static void __append_range(string& __dest, _Iter __b, _Iter __e) {
594 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
595 if (__b == __e) return;
596 basic_string<_ECharT> __tmp(__b, __e);
597 _Narrower()(back_inserter(__dest), __tmp.data(),
598 __tmp.data() + __tmp.length());
599 }
600
601 template <class _Iter>
602 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
603 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
604 const _ECharT __sentinal = _ECharT{};
605 if (*__b == __sentinal) return;
606 basic_string<_ECharT> __tmp;
607 for (; *__b != __sentinal; ++__b)
608 __tmp.push_back(*__b);
609 _Narrower()(back_inserter(__dest), __tmp.data(),
610 __tmp.data() + __tmp.length());
611 }
612
613 template <class _Source>
614 static void __append_source(string& __dest, _Source const& __s)
615 {
616 using _Traits = __is_pathable<_Source>;
617 __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
618 }
619};
620
621template <>
622struct _PathCVT<char> {
623 template <class _Iter>
624 static void __append_range(string& __dest, _Iter __b, _Iter __e) {
625 for (; __b != __e; ++__b)
626 __dest.push_back(*__b);
627 }
628
629 template <class _Iter>
630 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
631 const char __sentinal = char{};
632 for (; *__b != __sentinal; ++__b)
633 __dest.push_back(*__b);
634 }
635
636 template <class _Source>
637 static void __append_source(string& __dest, _Source const& __s)
638 {
639 using _Traits = __is_pathable<_Source>;
640 __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
641 }
642};
643
644
645class _LIBCPP_TYPE_VIS path
646{
647 template <class _SourceOrIter, class _Tp = path&>
648 using _EnableIfPathable = typename
649 enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
650
651 template <class _Tp>
652 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
653
654 template <class _Tp>
655 using _SourceCVT = _PathCVT<_SourceChar<_Tp>>;
656
657public:
658 typedef char value_type;
659 typedef basic_string<value_type> string_type;
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000660 typedef _VSTD::string_view __string_view;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000661 static _LIBCPP_CONSTEXPR value_type preferred_separator = '/';
662
663 // constructors and destructor
664 _LIBCPP_INLINE_VISIBILITY path() _NOEXCEPT {}
665 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
666 _LIBCPP_INLINE_VISIBILITY path(path&& __p) _NOEXCEPT : __pn_(_VSTD::move(__p.__pn_)) {}
667
668 _LIBCPP_INLINE_VISIBILITY
669 path(string_type&& __s) _NOEXCEPT : __pn_(_VSTD::move(__s)) {}
670
671 template <
672 class _Source,
673 class = _EnableIfPathable<_Source, void>
674 >
675 path(const _Source& __src) {
676 _SourceCVT<_Source>::__append_source(__pn_, __src);
677 }
678
679 template <class _InputIt>
680 path(_InputIt __first, _InputIt __last) {
681 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
682 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
683 }
684
685 // TODO Implement locale conversions.
686 template <class _Source,
687 class = _EnableIfPathable<_Source, void>
688 >
689 path(const _Source& __src, const locale& __loc);
690 template <class _InputIt>
691 path(_InputIt __first, _InputIt _last, const locale& __loc);
692
693 _LIBCPP_INLINE_VISIBILITY
694 ~path() = default;
695
696 // assignments
697 _LIBCPP_INLINE_VISIBILITY
698 path& operator=(const path& __p) {
699 __pn_ = __p.__pn_;
700 return *this;
701 }
702
703 _LIBCPP_INLINE_VISIBILITY
704 path& operator=(path&& __p) _NOEXCEPT {
705 __pn_ = _VSTD::move(__p.__pn_);
706 return *this;
707 }
708
709 _LIBCPP_INLINE_VISIBILITY
710 path& operator=(string_type&& __s) _NOEXCEPT {
711 __pn_ = _VSTD::move(__s);
712 return *this;
713 }
714
715 _LIBCPP_INLINE_VISIBILITY
716 path& assign(string_type&& __s) _NOEXCEPT {
717 __pn_ = _VSTD::move(__s);
718 return *this;
719 }
720
721 template <class _Source>
722 _LIBCPP_INLINE_VISIBILITY
723 _EnableIfPathable<_Source>
724 operator=(const _Source& __src)
725 { return this->assign(__src); }
726
727
728 template <class _Source>
729 _EnableIfPathable<_Source>
730 assign(const _Source& __src) {
731 __pn_.clear();
732 _SourceCVT<_Source>::__append_source(__pn_, __src);
733 return *this;
734 }
735
736 template <class _InputIt>
737 path& assign(_InputIt __first, _InputIt __last) {
738 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
739 __pn_.clear();
740 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
741 return *this;
742 }
743
744private:
745 template <class _ECharT>
746 void __append_sep_if_needed(_ECharT __first_or_null) {
747 const _ECharT __null_val = {};
748 bool __append_sep = !empty() &&
749 !__is_separator(__pn_.back()) &&
750 __first_or_null != __null_val && // non-empty
751 !__is_separator(__first_or_null);
752 if (__append_sep)
753 __pn_ += preferred_separator;
754 }
755
756public:
757 // appends
758 path& operator/=(const path& __p) {
759 __append_sep_if_needed(__p.empty() ? char{} : __p.__pn_[0]);
760 __pn_ += __p.native();
761 return *this;
762 }
763
764 template <class _Source>
765 _LIBCPP_INLINE_VISIBILITY
766 _EnableIfPathable<_Source>
767 operator/=(const _Source& __src) {
768 return this->append(__src);
769 }
770
771 template <class _Source>
772 _EnableIfPathable<_Source>
773 append(const _Source& __src) {
774 using _Traits = __is_pathable<_Source>;
775 using _CVT = _PathCVT<_SourceChar<_Source>>;
776 __append_sep_if_needed(_Traits::__first_or_null(__src));
777 _CVT::__append_source(__pn_, __src);
778 return *this;
779 }
780
781 template <class _InputIt>
782 path& append(_InputIt __first, _InputIt __last) {
783 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
784 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
785 using _CVT = _PathCVT<_ItVal>;
786 if (__first != __last) {
787 __append_sep_if_needed(*__first);
788 _CVT::__append_range(__pn_, __first, __last);
789 }
790 return *this;
791 }
792
793 // concatenation
794 _LIBCPP_INLINE_VISIBILITY
795 path& operator+=(const path& __x) {
796 __pn_ += __x.__pn_;
797 return *this;
798 }
799
800 _LIBCPP_INLINE_VISIBILITY
801 path& operator+=(const string_type& __x) {
802 __pn_ += __x;
803 return *this;
804 }
805
806 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000807 path& operator+=(__string_view __x) {
808 __pn_ += __x;
809 return *this;
810 }
811
812 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000813 path& operator+=(const value_type* __x) {
814 __pn_ += __x;
815 return *this;
816 }
817
818 _LIBCPP_INLINE_VISIBILITY
819 path& operator+=(value_type __x) {
820 __pn_ += __x;
821 return *this;
822 }
823
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000824 template <class _ECharT>
825 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
826 operator+=(_ECharT __x)
827 {
828 basic_string<_ECharT> __tmp;
829 __tmp += __x;
830 _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
831 return *this;
832 }
833
834 template <class _Source>
835 _EnableIfPathable<_Source>
836 operator+=(const _Source& __x) {
837 return this->concat(__x);
838 }
839
840 template <class _Source>
841 _EnableIfPathable<_Source>
842 concat(const _Source& __x) {
843 _SourceCVT<_Source>::__append_source(__pn_, __x);
844 return *this;
845 }
846
847 template <class _InputIt>
848 path& concat(_InputIt __first, _InputIt __last) {
849 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
850 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
851 return *this;
852 }
853
854 // modifiers
855 _LIBCPP_INLINE_VISIBILITY
856 void clear() _NOEXCEPT {
857 __pn_.clear();
858 }
859
860 path& make_preferred() { return *this; }
861 path& remove_filename() { return *this = parent_path(); }
862
863 path& replace_filename(const path& __replacement) {
864 remove_filename();
865 return (*this /= __replacement);
866 }
867
868 path& replace_extension(const path& __replacement = path());
869
870 _LIBCPP_INLINE_VISIBILITY
871 void swap(path& __rhs) _NOEXCEPT {
872 __pn_.swap(__rhs.__pn_);
873 }
874
875 // native format observers
876 _LIBCPP_INLINE_VISIBILITY
877 const string_type& native() const _NOEXCEPT {
878 return __pn_;
879 }
880
881 _LIBCPP_INLINE_VISIBILITY
882 const value_type* c_str() const _NOEXCEPT { return __pn_.c_str(); }
883
884 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
885
886 template <class _ECharT, class _Traits = char_traits<_ECharT>,
887 class _Allocator = allocator<_ECharT> >
888 basic_string<_ECharT, _Traits, _Allocator>
889 string(const _Allocator& __a = _Allocator()) const {
890 using _CVT = __widen_from_utf8<sizeof(_ECharT)*__CHAR_BIT__>;
891 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
892 _Str __s(__a);
893 __s.reserve(__pn_.size());
894 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
895 return __s;
896 }
897
898 _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
899 _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const { return string<wchar_t>(); }
900 _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
901 _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { return string<char16_t>(); }
902 _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { return string<char32_t>(); }
903
904 // generic format observers
905 template <class _ECharT, class _Traits = char_traits<_ECharT>,
906 class _Allocator = allocator<_ECharT>
907 >
908 basic_string<_ECharT, _Traits, _Allocator>
909 generic_string(const _Allocator& __a = _Allocator()) const {
910 return string<_ECharT, _Traits, _Allocator>(__a);
911 }
912
913 std::string generic_string() const { return __pn_; }
914 std::wstring generic_wstring() const { return string<wchar_t>(); }
915 std::string generic_u8string() const { return __pn_; }
916 std::u16string generic_u16string() const { return string<char16_t>(); }
917 std::u32string generic_u32string() const { return string<char32_t>(); }
918
919private:
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000920 _LIBCPP_FUNC_VIS int __compare(__string_view) const;
921 _LIBCPP_FUNC_VIS __string_view __root_name() const;
922 _LIBCPP_FUNC_VIS __string_view __root_directory() const;
923 _LIBCPP_FUNC_VIS __string_view __relative_path() const;
924 _LIBCPP_FUNC_VIS __string_view __parent_path() const;
925 _LIBCPP_FUNC_VIS __string_view __filename() const;
926 _LIBCPP_FUNC_VIS __string_view __stem() const;
927 _LIBCPP_FUNC_VIS __string_view __extension() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000928
929public:
930 // compare
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000931 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const _NOEXCEPT { return __compare(__p.__pn_);}
932 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); }
933 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000934 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { return __compare(__s); }
935
936 // decomposition
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000937 _LIBCPP_INLINE_VISIBILITY path root_name() const { return string_type(__root_name()); }
938 _LIBCPP_INLINE_VISIBILITY path root_directory() const { return string_type(__root_directory()); }
939 _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(string_type(__root_directory())); }
940 _LIBCPP_INLINE_VISIBILITY path relative_path() const { return string_type(__relative_path()); }
941 _LIBCPP_INLINE_VISIBILITY path parent_path() const { return string_type(__parent_path()); }
942 _LIBCPP_INLINE_VISIBILITY path filename() const { return string_type(__filename()); }
943 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem());}
944 _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000945
946 // query
947 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT { return __pn_.empty(); }
948
949 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); }
950 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); }
951 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !(__root_name().empty() && __root_directory().empty()); }
952 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { return !__relative_path().empty(); }
953 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { return !__parent_path().empty(); }
954 _LIBCPP_INLINE_VISIBILITY bool has_filename() const { return !__filename().empty(); }
955 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
956 _LIBCPP_INLINE_VISIBILITY bool has_extension() const { return !__extension().empty(); }
957
958 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { return has_root_directory(); }
959 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
960
961 // iterators
962 class _LIBCPP_TYPE_VIS iterator;
963 typedef iterator const_iterator;
964
965 _LIBCPP_FUNC_VIS iterator begin() const;
966 _LIBCPP_FUNC_VIS iterator end() const;
967
968private:
969 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000970 path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; }
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000971 string_type __pn_;
972};
973
974inline _LIBCPP_ALWAYS_INLINE
975void swap(path& __lhs, path& __rhs) _NOEXCEPT {
976 __lhs.swap(__rhs);
977}
978
979_LIBCPP_FUNC_VIS
980size_t hash_value(const path& __p) _NOEXCEPT;
981
982inline _LIBCPP_INLINE_VISIBILITY
983bool operator==(const path& __lhs, const path& __rhs) _NOEXCEPT
984{ return __lhs.compare(__rhs) == 0; }
985
986inline _LIBCPP_INLINE_VISIBILITY
987bool operator!=(const path& __lhs, const path& __rhs) _NOEXCEPT
988{ return __lhs.compare(__rhs) != 0; }
989
990inline _LIBCPP_INLINE_VISIBILITY
991bool operator<(const path& __lhs, const path& __rhs) _NOEXCEPT
992{ return __lhs.compare(__rhs) < 0; }
993
994inline _LIBCPP_INLINE_VISIBILITY
995bool operator<=(const path& __lhs, const path& __rhs) _NOEXCEPT
996{ return __lhs.compare(__rhs) <= 0; }
997
998inline _LIBCPP_INLINE_VISIBILITY
999bool operator>(const path& __lhs, const path& __rhs) _NOEXCEPT
1000{ return __lhs.compare(__rhs) > 0; }
1001
1002inline _LIBCPP_INLINE_VISIBILITY
1003bool operator>=(const path& __lhs, const path& __rhs) _NOEXCEPT
1004{ return __lhs.compare(__rhs) >= 0; }
1005
1006inline _LIBCPP_INLINE_VISIBILITY
1007path operator/(const path& __lhs, const path& __rhs) {
1008 return path(__lhs) /= __rhs;
1009}
1010
1011template <class _CharT, class _Traits>
1012_LIBCPP_INLINE_VISIBILITY
1013typename enable_if<is_same<_CharT, char>::value &&
1014 is_same<_Traits, char_traits<char>>::value,
1015 basic_ostream<_CharT, _Traits>&
1016>::type
1017operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1018 __os << std::__quoted(__p.native());
1019 return __os;
1020}
1021
1022template <class _CharT, class _Traits>
1023_LIBCPP_INLINE_VISIBILITY
1024typename enable_if<!is_same<_CharT, char>::value ||
1025 !is_same<_Traits, char_traits<char>>::value,
1026 basic_ostream<_CharT, _Traits>&
1027>::type
1028operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1029 __os << std::__quoted(__p.string<_CharT, _Traits>());
1030 return __os;
1031}
1032
1033template <class _CharT, class _Traits>
1034_LIBCPP_INLINE_VISIBILITY
1035basic_istream<_CharT, _Traits>&
1036operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
1037{
1038 basic_string<_CharT, _Traits> __tmp;
1039 __is >> __quoted(__tmp);
1040 __p = __tmp;
1041 return __is;
1042}
1043
1044template <class _Source>
1045_LIBCPP_INLINE_VISIBILITY
1046typename enable_if<__is_pathable<_Source>::value, path>::type
1047u8path(const _Source& __s){
1048 static_assert(is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1049 "u8path(Source const&) requires Source have a character type of type 'char'");
1050 return path(__s);
1051}
1052
1053template <class _InputIt>
1054_LIBCPP_INLINE_VISIBILITY
1055typename enable_if<__is_pathable<_InputIt>::value, path>::type
1056u8path(_InputIt __f, _InputIt __l) {
1057 static_assert(is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1058 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1059 return path(__f, __l);
1060}
1061
1062class _LIBCPP_TYPE_VIS path::iterator
1063{
1064public:
1065 typedef bidirectional_iterator_tag iterator_category;
1066 typedef path value_type;
1067 typedef std::ptrdiff_t difference_type;
1068 typedef const path* pointer;
1069 typedef const path& reference;
1070public:
1071 _LIBCPP_INLINE_VISIBILITY
1072 iterator() : __elem_(), __path_ptr_(nullptr), __pos_(0) {}
1073
1074 iterator(const iterator&) = default;
1075 ~iterator() = default;
1076
1077 iterator& operator=(const iterator&) = default;
1078
1079 _LIBCPP_INLINE_VISIBILITY
1080 reference operator*() const {
1081 return __elem_;
1082 }
1083
1084 _LIBCPP_INLINE_VISIBILITY
1085 pointer operator->() const {
1086 return &__elem_;
1087 }
1088
1089 _LIBCPP_INLINE_VISIBILITY
1090 iterator& operator++() {
1091 return __increment();
1092 }
1093
1094 _LIBCPP_INLINE_VISIBILITY
1095 iterator operator++(int) {
1096 iterator __it(*this);
1097 this->operator++();
1098 return __it;
1099 }
1100
1101 _LIBCPP_INLINE_VISIBILITY
1102 iterator& operator--() {
1103 return __decrement();
1104 }
1105
1106 _LIBCPP_INLINE_VISIBILITY
1107 iterator operator--(int) {
1108 iterator __it(*this);
1109 this->operator--();
1110 return __it;
1111 }
1112
1113private:
1114 friend class path;
1115 friend bool operator==(const iterator&, const iterator&);
1116
1117 _LIBCPP_FUNC_VIS iterator& __increment();
1118 _LIBCPP_FUNC_VIS iterator& __decrement();
1119
1120 path __elem_;
1121 const path* __path_ptr_;
1122 size_t __pos_;
1123};
1124
1125inline _LIBCPP_INLINE_VISIBILITY
1126bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) {
1127 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
1128 __lhs.__pos_ == __rhs.__pos_;
1129}
1130
1131inline _LIBCPP_INLINE_VISIBILITY
1132bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) {
1133 return !(__lhs == __rhs);
1134}
1135
1136class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error
1137{
1138public:
1139 _LIBCPP_INLINE_VISIBILITY
1140 filesystem_error(const string& __what, error_code __ec)
1141 : system_error(__ec, __what),
1142 __paths_(make_shared<_Storage>(path(), path()))
1143 {}
1144
1145 _LIBCPP_INLINE_VISIBILITY
1146 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1147 : system_error(__ec, __what),
1148 __paths_(make_shared<_Storage>(__p1, path()))
1149 {}
1150
1151 _LIBCPP_INLINE_VISIBILITY
1152 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1153 error_code __ec)
1154 : system_error(__ec, __what),
1155 __paths_(make_shared<_Storage>(__p1, __p2))
1156 {}
1157
1158 _LIBCPP_INLINE_VISIBILITY
1159 const path& path1() const _NOEXCEPT {
1160 return __paths_->first;
1161 }
1162
1163 _LIBCPP_INLINE_VISIBILITY
1164 const path& path2() const _NOEXCEPT {
1165 return __paths_->second;
1166 }
1167
1168 _LIBCPP_FUNC_VIS
1169 ~filesystem_error() override; // key function
1170
1171 // TODO(ericwf): Create a custom error message.
1172 //const char* what() const _NOEXCEPT;
1173
1174private:
1175 typedef pair<path, path> _Storage;
1176 shared_ptr<_Storage> __paths_;
1177};
1178
1179// operational functions
1180
1181_LIBCPP_FUNC_VIS
1182path __canonical(const path&, const path&, error_code *__ec=nullptr);
1183_LIBCPP_FUNC_VIS
1184void __copy(const path& __from, const path& __to, copy_options __opt,
1185 error_code *__ec=nullptr);
1186_LIBCPP_FUNC_VIS
1187bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1188 error_code *__ec=nullptr);
1189_LIBCPP_FUNC_VIS
1190void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1191 error_code *__ec=nullptr);
1192_LIBCPP_FUNC_VIS
1193bool __create_directories(const path& p, error_code *ec=nullptr);
1194_LIBCPP_FUNC_VIS
1195bool __create_directory(const path& p, error_code *ec=nullptr);
1196_LIBCPP_FUNC_VIS
1197bool __create_directory(const path& p, const path & attributes,
1198 error_code *ec=nullptr);
1199_LIBCPP_FUNC_VIS
1200void __create_directory_symlink(const path& __to, const path& __new_symlink,
1201 error_code *__ec=nullptr);
1202_LIBCPP_FUNC_VIS
1203void __create_hard_link(const path& __to, const path& __new_hard_link,
1204 error_code *__ec=nullptr);
1205_LIBCPP_FUNC_VIS
1206void __create_symlink(const path& __to, const path& __new_symlink,
1207 error_code *__ec=nullptr);
1208_LIBCPP_FUNC_VIS
1209path __current_path(error_code *__ec=nullptr);
1210_LIBCPP_FUNC_VIS
1211void __current_path(const path&, error_code *__ec=nullptr);
1212_LIBCPP_FUNC_VIS
1213bool __equivalent(const path&, const path&, error_code *__ec=nullptr);
1214_LIBCPP_FUNC_VIS
1215uintmax_t __file_size(const path&, error_code *__ec=nullptr);
1216_LIBCPP_FUNC_VIS
1217uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr);
1218_LIBCPP_FUNC_VIS
1219bool __fs_is_empty(const path& p, error_code *ec=nullptr);
1220_LIBCPP_FUNC_VIS
1221file_time_type __last_write_time(const path& p, error_code *ec=nullptr);
1222_LIBCPP_FUNC_VIS
1223void __last_write_time(const path& p, file_time_type new_time,
1224 error_code *ec=nullptr);
1225_LIBCPP_FUNC_VIS
1226void __permissions(const path& p, perms prms, error_code *ec=nullptr);
1227_LIBCPP_FUNC_VIS
1228path __read_symlink(const path& p, error_code *ec=nullptr);
1229_LIBCPP_FUNC_VIS
1230bool __remove(const path& p, error_code *ec=nullptr);
1231_LIBCPP_FUNC_VIS
1232uintmax_t __remove_all(const path& p, error_code *ec=nullptr);
1233_LIBCPP_FUNC_VIS
1234void __rename(const path& from, const path& to, error_code *ec=nullptr);
1235_LIBCPP_FUNC_VIS
1236void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr);
1237_LIBCPP_FUNC_VIS
1238space_info __space(const path&, error_code *__ec=nullptr);
1239_LIBCPP_FUNC_VIS
1240file_status __status(const path&, error_code *__ec=nullptr);
1241_LIBCPP_FUNC_VIS
1242file_status __symlink_status(const path&, error_code *__ec=nullptr);
1243_LIBCPP_FUNC_VIS
1244path __system_complete(const path&, error_code *__ec=nullptr);
1245_LIBCPP_FUNC_VIS
1246path __temp_directory_path(error_code *__ec=nullptr);
1247
1248inline _LIBCPP_INLINE_VISIBILITY
1249path current_path() {
1250 return __current_path();
1251}
1252
1253inline _LIBCPP_INLINE_VISIBILITY
1254path current_path(error_code& __ec) {
1255 return __current_path(&__ec);
1256}
1257
1258inline _LIBCPP_INLINE_VISIBILITY
1259void current_path(const path& __p) {
1260 __current_path(__p);
1261}
1262
1263inline _LIBCPP_INLINE_VISIBILITY
1264void current_path(const path& __p, error_code& __ec) _NOEXCEPT {
1265 __current_path(__p, &__ec);
1266}
1267
1268_LIBCPP_FUNC_VIS
1269path absolute(const path&, const path& __p2 = current_path());
1270
1271inline _LIBCPP_INLINE_VISIBILITY
1272path canonical(const path& __p, const path& __base = current_path()) {
1273 return __canonical(__p, __base);
1274}
1275
1276inline _LIBCPP_INLINE_VISIBILITY
1277path canonical(const path& __p, error_code& __ec) {
1278 path __base = __current_path(&__ec);
1279 if (__ec) return {};
1280 return __canonical(__p, __base, &__ec);
1281}
1282
1283inline _LIBCPP_INLINE_VISIBILITY
1284path canonical(const path& __p, const path& __base, error_code& __ec) {
1285 return __canonical(__p, __base, &__ec);
1286}
1287
1288inline _LIBCPP_INLINE_VISIBILITY
1289void copy(const path& __from, const path& __to) {
1290 __copy(__from, __to, copy_options::none);
1291}
1292
1293inline _LIBCPP_INLINE_VISIBILITY
1294void copy(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
1295 __copy(__from, __to, copy_options::none, &__ec);
1296}
1297
1298inline _LIBCPP_INLINE_VISIBILITY
1299void copy(const path& __from, const path& __to, copy_options __opt) {
1300 __copy(__from, __to, __opt);
1301}
1302
1303inline _LIBCPP_INLINE_VISIBILITY
1304void copy(const path& __from, const path& __to,
1305 copy_options __opt, error_code& __ec) _NOEXCEPT {
1306 __copy(__from, __to, __opt, &__ec);
1307}
1308
1309inline _LIBCPP_INLINE_VISIBILITY
1310bool copy_file(const path& __from, const path& __to) {
1311 return __copy_file(__from, __to, copy_options::none);
1312}
1313
1314inline _LIBCPP_INLINE_VISIBILITY
1315bool copy_file(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
1316 return __copy_file(__from, __to, copy_options::none, &__ec);
1317}
1318
1319inline _LIBCPP_INLINE_VISIBILITY
1320bool copy_file(const path& __from, const path& __to, copy_options __opt) {
1321 return __copy_file(__from, __to, __opt);
1322}
1323
1324inline _LIBCPP_INLINE_VISIBILITY
1325bool copy_file(const path& __from, const path& __to,
1326 copy_options __opt, error_code& __ec) _NOEXCEPT {
1327 return __copy_file(__from, __to, __opt, &__ec);
1328}
1329
1330inline _LIBCPP_INLINE_VISIBILITY
1331void copy_symlink(const path& __existing, const path& __new) {
1332 __copy_symlink(__existing, __new);
1333}
1334
1335inline _LIBCPP_INLINE_VISIBILITY
1336void copy_symlink(const path& __ext, const path& __new, error_code& __ec) _NOEXCEPT {
1337 __copy_symlink(__ext, __new, &__ec);
1338}
1339
1340inline _LIBCPP_INLINE_VISIBILITY
1341bool create_directories(const path& __p) {
1342 return __create_directories(__p);
1343}
1344
1345inline _LIBCPP_INLINE_VISIBILITY
1346bool create_directories(const path& __p, error_code& __ec) _NOEXCEPT {
1347 return __create_directories(__p, &__ec);
1348}
1349
1350inline _LIBCPP_INLINE_VISIBILITY
1351bool create_directory(const path& __p) {
1352 return __create_directory(__p);
1353}
1354
1355inline _LIBCPP_INLINE_VISIBILITY
1356bool create_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1357 return __create_directory(__p, &__ec);
1358}
1359
1360inline _LIBCPP_INLINE_VISIBILITY
1361bool create_directory(const path& __p, const path& __attrs) {
1362 return __create_directory(__p, __attrs);
1363}
1364
1365inline _LIBCPP_INLINE_VISIBILITY
1366bool create_directory(const path& __p, const path& __attrs, error_code& __ec) _NOEXCEPT {
1367 return __create_directory(__p, __attrs, &__ec);
1368}
1369
1370inline _LIBCPP_INLINE_VISIBILITY
1371void create_directory_symlink(const path& __to, const path& __new) {
1372 __create_directory_symlink(__to, __new);
1373}
1374
1375inline _LIBCPP_INLINE_VISIBILITY
1376void create_directory_symlink(const path& __to, const path& __new,
1377 error_code& __ec) _NOEXCEPT {
1378 __create_directory_symlink(__to, __new, &__ec);
1379}
1380
1381inline _LIBCPP_INLINE_VISIBILITY
1382void create_hard_link(const path& __to, const path& __new) {
1383 __create_hard_link(__to, __new);
1384}
1385
1386inline _LIBCPP_INLINE_VISIBILITY
1387void create_hard_link(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
1388 __create_hard_link(__to, __new, &__ec);
1389}
1390
1391inline _LIBCPP_INLINE_VISIBILITY
1392void create_symlink(const path& __to, const path& __new) {
1393 __create_symlink(__to, __new);
1394}
1395
1396inline _LIBCPP_INLINE_VISIBILITY
1397void create_symlink(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
1398 return __create_symlink(__to, __new, &__ec);
1399}
1400
1401inline _LIBCPP_INLINE_VISIBILITY
1402bool status_known(file_status __s) _NOEXCEPT {
1403 return __s.type() != file_type::none;
1404}
1405
1406inline _LIBCPP_INLINE_VISIBILITY
1407bool exists(file_status __s) _NOEXCEPT {
1408 return status_known(__s) && __s.type() != file_type::not_found;
1409}
1410
1411inline _LIBCPP_INLINE_VISIBILITY
1412bool exists(const path& __p) {
1413 return exists(__status(__p));
1414}
1415
1416inline _LIBCPP_INLINE_VISIBILITY
1417bool exists(const path& __p, error_code& __ec) _NOEXCEPT {
Eric Fiselier756a6bd2016-06-21 22:11:16 +00001418 auto __s = __status(__p, &__ec);
1419 if (status_known(__s)) __ec.clear();
1420 return exists(__s);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001421}
1422
1423inline _LIBCPP_INLINE_VISIBILITY
1424bool equivalent(const path& __p1, const path& __p2) {
1425 return __equivalent(__p1, __p2);
1426}
1427
1428inline _LIBCPP_INLINE_VISIBILITY
1429bool equivalent(const path& __p1, const path& __p2, error_code& __ec) _NOEXCEPT {
1430 return __equivalent(__p1, __p2, &__ec);
1431}
1432
1433inline _LIBCPP_INLINE_VISIBILITY
1434uintmax_t file_size(const path& __p) {
1435 return __file_size(__p);
1436}
1437
1438inline _LIBCPP_INLINE_VISIBILITY
1439uintmax_t file_size(const path& __p, error_code& __ec) _NOEXCEPT {
1440 return __file_size(__p, &__ec);
1441}
1442
1443inline _LIBCPP_INLINE_VISIBILITY
1444uintmax_t hard_link_count(const path& __p) {
1445 return __hard_link_count(__p);
1446}
1447
1448inline _LIBCPP_INLINE_VISIBILITY
1449uintmax_t hard_link_count(const path& __p, error_code& __ec) _NOEXCEPT {
1450 return __hard_link_count(__p, &__ec);
1451}
1452
1453inline _LIBCPP_INLINE_VISIBILITY
1454bool is_block_file(file_status __s) _NOEXCEPT {
1455 return __s.type() == file_type::block;
1456}
1457
1458inline _LIBCPP_INLINE_VISIBILITY
1459bool is_block_file(const path& __p) {
1460 return is_block_file(__status(__p));
1461}
1462
1463inline _LIBCPP_INLINE_VISIBILITY
1464bool is_block_file(const path& __p, error_code& __ec) _NOEXCEPT {
1465 return is_block_file(__status(__p, &__ec));
1466}
1467
1468inline _LIBCPP_INLINE_VISIBILITY
1469bool is_character_file(file_status __s) _NOEXCEPT {
1470 return __s.type() == file_type::character;
1471}
1472
1473inline _LIBCPP_INLINE_VISIBILITY
1474bool is_character_file(const path& __p) {
1475 return is_character_file(__status(__p));
1476}
1477
1478inline _LIBCPP_INLINE_VISIBILITY
1479bool is_character_file(const path& __p, error_code& __ec) _NOEXCEPT {
1480 return is_character_file(__status(__p, &__ec));
1481}
1482
1483inline _LIBCPP_INLINE_VISIBILITY
1484bool is_directory(file_status __s) _NOEXCEPT {
1485 return __s.type() == file_type::directory;
1486}
1487
1488inline _LIBCPP_INLINE_VISIBILITY
1489bool is_directory(const path& __p) {
1490 return is_directory(__status(__p));
1491}
1492
1493inline _LIBCPP_INLINE_VISIBILITY
1494bool is_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1495 return is_directory(__status(__p, &__ec));
1496}
1497
1498inline _LIBCPP_INLINE_VISIBILITY
1499bool is_empty(const path& __p) {
1500 return __fs_is_empty(__p);
1501}
1502
1503inline _LIBCPP_INLINE_VISIBILITY
1504bool is_empty(const path& __p, error_code& __ec) _NOEXCEPT {
1505 return __fs_is_empty(__p, &__ec);
1506}
1507
1508inline _LIBCPP_INLINE_VISIBILITY
1509bool is_fifo(file_status __s) _NOEXCEPT {
1510 return __s.type() == file_type::fifo;
1511}
1512inline _LIBCPP_INLINE_VISIBILITY
1513bool is_fifo(const path& __p) {
1514 return is_fifo(__status(__p));
1515}
1516
1517inline _LIBCPP_INLINE_VISIBILITY
1518bool is_fifo(const path& __p, error_code& __ec) _NOEXCEPT {
1519 return is_fifo(__status(__p, &__ec));
1520}
1521
1522inline _LIBCPP_INLINE_VISIBILITY
1523bool is_regular_file(file_status __s) _NOEXCEPT {
1524 return __s.type() == file_type::regular;
1525}
1526
1527inline _LIBCPP_INLINE_VISIBILITY
1528bool is_regular_file(const path& __p) {
1529 return is_regular_file(__status(__p));
1530}
1531
1532inline _LIBCPP_INLINE_VISIBILITY
1533bool is_regular_file(const path& __p, error_code& __ec) _NOEXCEPT {
1534 return is_regular_file(__status(__p, &__ec));
1535}
1536
1537inline _LIBCPP_INLINE_VISIBILITY
1538bool is_socket(file_status __s) _NOEXCEPT {
1539 return __s.type() == file_type::socket;
1540}
1541
1542inline _LIBCPP_INLINE_VISIBILITY
1543bool is_socket(const path& __p) {
1544 return is_socket(__status(__p));
1545}
1546
1547inline _LIBCPP_INLINE_VISIBILITY
1548bool is_socket(const path& __p, error_code& __ec) _NOEXCEPT {
1549 return is_socket(__status(__p, &__ec));
1550}
1551
1552inline _LIBCPP_INLINE_VISIBILITY
1553bool is_symlink(file_status __s) _NOEXCEPT {
1554 return __s.type() == file_type::symlink;
1555}
1556
1557inline _LIBCPP_INLINE_VISIBILITY
1558bool is_symlink(const path& __p) {
1559 return is_symlink(__symlink_status(__p));
1560}
1561
1562inline _LIBCPP_INLINE_VISIBILITY
1563bool is_symlink(const path& __p, error_code& __ec) _NOEXCEPT {
1564 return is_symlink(__symlink_status(__p, &__ec));
1565}
1566
1567inline _LIBCPP_INLINE_VISIBILITY
1568bool is_other(file_status __s) _NOEXCEPT {
1569 return exists(__s)
1570 && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s);
1571}
1572
1573inline _LIBCPP_INLINE_VISIBILITY
1574bool is_other(const path& __p) {
1575 return is_other(__status(__p));
1576}
1577
1578inline _LIBCPP_INLINE_VISIBILITY
1579bool is_other(const path& __p, error_code& __ec) _NOEXCEPT {
1580 return is_other(__status(__p, &__ec));
1581}
1582
1583inline _LIBCPP_INLINE_VISIBILITY
1584file_time_type last_write_time(const path& __p) {
1585 return __last_write_time(__p);
1586}
1587
1588inline _LIBCPP_INLINE_VISIBILITY
1589file_time_type last_write_time(const path& __p, error_code& __ec) _NOEXCEPT {
1590 return __last_write_time(__p, &__ec);
1591}
1592
1593inline _LIBCPP_INLINE_VISIBILITY
1594void last_write_time(const path& __p, file_time_type __t) {
1595 __last_write_time(__p, __t);
1596}
1597
1598inline _LIBCPP_INLINE_VISIBILITY
1599void last_write_time(const path& __p, file_time_type __t, error_code& __ec) _NOEXCEPT {
1600 __last_write_time(__p, __t, &__ec);
1601}
1602
1603inline _LIBCPP_INLINE_VISIBILITY
1604void permissions(const path& __p, perms __prms) {
1605 __permissions(__p, __prms);
1606}
1607
1608inline _LIBCPP_INLINE_VISIBILITY
1609void permissions(const path& __p, perms __prms, error_code& __ec) {
1610 __permissions(__p, __prms, &__ec);
1611}
1612
1613inline _LIBCPP_INLINE_VISIBILITY
1614path read_symlink(const path& __p) {
1615 return __read_symlink(__p);
1616}
1617
1618inline _LIBCPP_INLINE_VISIBILITY
1619path read_symlink(const path& __p, error_code& __ec) {
1620 return __read_symlink(__p, &__ec);
1621}
1622
1623inline _LIBCPP_INLINE_VISIBILITY
1624bool remove(const path& __p) {
1625 return __remove(__p);
1626}
1627
1628inline _LIBCPP_INLINE_VISIBILITY
1629bool remove(const path& __p, error_code& __ec) _NOEXCEPT {
1630 return __remove(__p, &__ec);
1631}
1632
1633inline _LIBCPP_INLINE_VISIBILITY
1634uintmax_t remove_all(const path& __p) {
1635 return __remove_all(__p);
1636}
1637
1638inline _LIBCPP_INLINE_VISIBILITY
1639uintmax_t remove_all(const path& __p, error_code& __ec) _NOEXCEPT {
1640 return __remove_all(__p, &__ec);
1641}
1642
1643inline _LIBCPP_INLINE_VISIBILITY
1644void rename(const path& __from, const path& __to) {
1645 return __rename(__from, __to);
1646}
1647
1648inline _LIBCPP_INLINE_VISIBILITY
1649void rename(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
1650 return __rename(__from, __to, &__ec);
1651}
1652
1653inline _LIBCPP_INLINE_VISIBILITY
1654void resize_file(const path& __p, uintmax_t __ns) {
1655 return __resize_file(__p, __ns);
1656}
1657
1658inline _LIBCPP_INLINE_VISIBILITY
1659void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) _NOEXCEPT {
1660 return __resize_file(__p, __ns, &__ec);
1661}
1662
1663inline _LIBCPP_INLINE_VISIBILITY
1664space_info space(const path& __p) {
1665 return __space(__p);
1666}
1667
1668inline _LIBCPP_INLINE_VISIBILITY
1669space_info space(const path& __p, error_code& __ec) _NOEXCEPT {
1670 return __space(__p, &__ec);
1671}
1672
1673inline _LIBCPP_INLINE_VISIBILITY
1674file_status status(const path& __p) {
1675 return __status(__p);
1676}
1677
1678inline _LIBCPP_INLINE_VISIBILITY
1679file_status status(const path& __p, error_code& __ec) _NOEXCEPT {
1680 return __status(__p, &__ec);
1681}
1682
1683inline _LIBCPP_INLINE_VISIBILITY
1684file_status symlink_status(const path& __p) {
1685 return __symlink_status(__p);
1686}
1687
1688inline _LIBCPP_INLINE_VISIBILITY
1689file_status symlink_status(const path& __p, error_code& __ec) _NOEXCEPT {
1690 return __symlink_status(__p, &__ec);
1691}
1692
1693inline _LIBCPP_INLINE_VISIBILITY
1694path system_complete(const path& __p) {
1695 return __system_complete(__p);
1696}
1697
1698inline _LIBCPP_INLINE_VISIBILITY
1699path system_complete(const path& __p, error_code& __ec) {
1700 return __system_complete(__p, &__ec);
1701}
1702
1703inline _LIBCPP_INLINE_VISIBILITY
1704path temp_directory_path() {
1705 return __temp_directory_path();
1706}
1707
1708inline _LIBCPP_INLINE_VISIBILITY
1709path temp_directory_path(error_code& __ec) {
1710 return __temp_directory_path(&__ec);
1711}
1712
1713
1714class directory_entry
1715{
1716 typedef _VSTD_FS::path _Path;
1717
1718public:
1719 // constructors and destructors
1720 directory_entry() _NOEXCEPT = default;
1721 directory_entry(directory_entry const&) = default;
1722 directory_entry(directory_entry&&) _NOEXCEPT = default;
1723
1724 _LIBCPP_INLINE_VISIBILITY
1725 explicit directory_entry(_Path const& __p) : __p_(__p) {}
1726
1727 ~directory_entry() {}
1728
1729 directory_entry& operator=(directory_entry const&) = default;
1730 directory_entry& operator=(directory_entry&&) _NOEXCEPT = default;
1731
1732 _LIBCPP_INLINE_VISIBILITY
1733 void assign(_Path const& __p) {
1734 __p_ = __p;
1735 }
1736
1737 _LIBCPP_INLINE_VISIBILITY
1738 void replace_filename(_Path const& __p) {
1739 __p_ = __p_.parent_path() / __p;
1740 }
1741
1742 _LIBCPP_INLINE_VISIBILITY
1743 _Path const& path() const _NOEXCEPT {
1744 return __p_;
1745 }
1746
1747 _LIBCPP_INLINE_VISIBILITY
1748 operator const _Path&() const _NOEXCEPT {
1749 return __p_;
1750 }
1751
1752 _LIBCPP_INLINE_VISIBILITY
1753 file_status status() const {
1754 return _VSTD_FS::status(__p_);
1755 }
1756
1757 _LIBCPP_INLINE_VISIBILITY
1758 file_status status(error_code& __ec) const _NOEXCEPT {
1759 return _VSTD_FS::status(__p_, __ec);
1760 }
1761
1762 _LIBCPP_INLINE_VISIBILITY
1763 file_status symlink_status() const {
1764 return _VSTD_FS::symlink_status(__p_);
1765 }
1766
1767 _LIBCPP_INLINE_VISIBILITY
1768 file_status symlink_status(error_code& __ec) const _NOEXCEPT {
1769 return _VSTD_FS::symlink_status(__p_, __ec);
1770 }
1771
1772 _LIBCPP_INLINE_VISIBILITY
1773 bool operator< (directory_entry const& __rhs) const _NOEXCEPT {
1774 return __p_ < __rhs.__p_;
1775 }
1776
1777 _LIBCPP_INLINE_VISIBILITY
1778 bool operator==(directory_entry const& __rhs) const _NOEXCEPT {
1779 return __p_ == __rhs.__p_;
1780 }
1781
1782 _LIBCPP_INLINE_VISIBILITY
1783 bool operator!=(directory_entry const& __rhs) const _NOEXCEPT {
1784 return __p_ != __rhs.__p_;
1785 }
1786
1787 _LIBCPP_INLINE_VISIBILITY
1788 bool operator<=(directory_entry const& __rhs) const _NOEXCEPT {
1789 return __p_ <= __rhs.__p_;
1790 }
1791
1792 _LIBCPP_INLINE_VISIBILITY
1793 bool operator> (directory_entry const& __rhs) const _NOEXCEPT {
1794 return __p_ > __rhs.__p_;
1795 }
1796
1797 _LIBCPP_INLINE_VISIBILITY
1798 bool operator>=(directory_entry const& __rhs) const _NOEXCEPT {
1799 return __p_ >= __rhs.__p_;
1800 }
1801private:
1802 _Path __p_;
1803};
1804
1805
1806class directory_iterator;
1807class recursive_directory_iterator;
1808class __dir_stream;
1809
1810class __dir_element_proxy {
1811public:
1812
1813 inline _LIBCPP_INLINE_VISIBILITY
1814 directory_entry operator*() { return _VSTD::move(__elem_); }
1815
1816private:
1817 friend class directory_iterator;
1818 friend class recursive_directory_iterator;
1819 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
1820 __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {}
1821 directory_entry __elem_;
1822};
1823
1824class directory_iterator
1825{
1826public:
1827 typedef directory_entry value_type;
1828 typedef ptrdiff_t difference_type;
1829 typedef value_type const* pointer;
1830 typedef value_type const& reference;
1831 typedef input_iterator_tag iterator_category;
1832
1833public:
1834 //ctor & dtor
1835 directory_iterator() _NOEXCEPT
1836 { }
1837
1838 explicit directory_iterator(const path& __p)
1839 : directory_iterator(__p, nullptr)
1840 { }
1841
1842 directory_iterator(const path& __p, directory_options __opts)
1843 : directory_iterator(__p, nullptr, __opts)
1844 { }
1845
1846 directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT
1847 : directory_iterator(__p, &__ec)
1848 { }
1849
1850 directory_iterator(const path& __p, directory_options __opts,
1851 error_code& __ec) _NOEXCEPT
1852 : directory_iterator(__p, &__ec, __opts)
1853 { }
1854
1855 directory_iterator(const directory_iterator&) = default;
1856 directory_iterator(directory_iterator&&) = default;
1857 directory_iterator& operator=(const directory_iterator&) = default;
1858
1859 directory_iterator& operator=(directory_iterator&& __o) _NOEXCEPT {
1860 // non-default implementation provided to support self-move assign.
1861 if (this != &__o) {
1862 __imp_ = _VSTD::move(__o.__imp_);
1863 }
1864 return *this;
1865 }
1866
1867 ~directory_iterator() = default;
1868
1869 const directory_entry& operator*() const {
1870 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
1871 return __deref();
1872 }
1873
1874 const directory_entry* operator->() const
1875 { return &**this; }
1876
1877 directory_iterator& operator++()
1878 { return __increment(); }
1879
1880 __dir_element_proxy operator++(int) {
1881 __dir_element_proxy __p(**this);
1882 __increment();
1883 return __p;
1884 }
1885
1886 directory_iterator& increment(error_code& __ec) _NOEXCEPT
1887 { return __increment(&__ec); }
1888
1889private:
1890 friend bool operator==(const directory_iterator& __lhs,
1891 const directory_iterator& __rhs) _NOEXCEPT;
1892
1893 // construct the dir_stream
1894 _LIBCPP_FUNC_VIS
1895 directory_iterator(const path&, error_code *, directory_options = directory_options::none);
1896 _LIBCPP_FUNC_VIS
1897 directory_iterator& __increment(error_code * __ec = nullptr);
1898 _LIBCPP_FUNC_VIS
1899 const directory_entry& __deref() const;
1900
1901private:
1902 shared_ptr<__dir_stream> __imp_;
1903};
1904
1905
1906inline _LIBCPP_INLINE_VISIBILITY
1907bool operator==(const directory_iterator& __lhs,
1908 const directory_iterator& __rhs) _NOEXCEPT {
1909 return __lhs.__imp_ == __rhs.__imp_;
1910}
1911
1912inline _LIBCPP_INLINE_VISIBILITY
1913bool operator!=(const directory_iterator& __lhs,
1914 const directory_iterator& __rhs) _NOEXCEPT {
1915 return !(__lhs == __rhs);
1916}
1917
1918// enable directory_iterator range-based for statements
1919inline _LIBCPP_INLINE_VISIBILITY
1920directory_iterator begin(directory_iterator __iter) _NOEXCEPT {
1921 return __iter;
1922}
1923
1924inline _LIBCPP_INLINE_VISIBILITY
1925directory_iterator end(const directory_iterator&) _NOEXCEPT {
1926 return directory_iterator();
1927}
1928
1929class recursive_directory_iterator {
1930public:
1931 using value_type = directory_entry;
1932 using difference_type = std::ptrdiff_t;
1933 using pointer = directory_entry const *;
1934 using reference = directory_entry const &;
1935 using iterator_category = std::input_iterator_tag;
1936
1937public:
1938 // constructors and destructor
1939 _LIBCPP_INLINE_VISIBILITY
1940 recursive_directory_iterator() _NOEXCEPT
1941 : __rec_(false)
1942 {}
1943
1944 _LIBCPP_INLINE_VISIBILITY
1945 explicit recursive_directory_iterator(const path& __p,
1946 directory_options __xoptions = directory_options::none)
1947 : recursive_directory_iterator(__p, __xoptions, nullptr)
1948 { }
1949
1950 _LIBCPP_INLINE_VISIBILITY
1951 recursive_directory_iterator(const path& __p,
1952 directory_options __xoptions, error_code& __ec) _NOEXCEPT
1953 : recursive_directory_iterator(__p, __xoptions, &__ec)
1954 { }
1955
1956 _LIBCPP_INLINE_VISIBILITY
1957 recursive_directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT
1958 : recursive_directory_iterator(__p, directory_options::none, &__ec)
1959 { }
1960
1961 recursive_directory_iterator(const recursive_directory_iterator&) = default;
1962 recursive_directory_iterator(recursive_directory_iterator&&) = default;
1963
1964 recursive_directory_iterator &
1965 operator=(const recursive_directory_iterator&) = default;
1966
1967 _LIBCPP_INLINE_VISIBILITY
1968 recursive_directory_iterator &
1969 operator=(recursive_directory_iterator&& __o) noexcept {
1970 // non-default implementation provided to support self-move assign.
1971 if (this != &__o) {
1972 __imp_ = _VSTD::move(__o.__imp_);
1973 __rec_ = __o.__rec_;
1974 }
1975 return *this;
1976 }
1977
1978 ~recursive_directory_iterator() = default;
1979
1980 _LIBCPP_INLINE_VISIBILITY
1981 const directory_entry& operator*() const
1982 { return __deref(); }
1983
1984 _LIBCPP_INLINE_VISIBILITY
1985 const directory_entry* operator->() const
1986 { return &__deref(); }
1987
1988 recursive_directory_iterator& operator++()
1989 { return __increment(); }
1990
1991 _LIBCPP_INLINE_VISIBILITY
1992 __dir_element_proxy operator++(int) {
1993 __dir_element_proxy __p(**this);
1994 __increment();
1995 return __p;
1996 }
1997
1998 _LIBCPP_INLINE_VISIBILITY
1999 recursive_directory_iterator& increment(error_code& __ec) _NOEXCEPT
2000 { return __increment(&__ec); }
2001
2002 _LIBCPP_FUNC_VIS directory_options options() const;
2003 _LIBCPP_FUNC_VIS int depth() const;
2004
2005 _LIBCPP_INLINE_VISIBILITY
2006 void pop() { __pop(); }
2007
2008 _LIBCPP_INLINE_VISIBILITY
2009 void pop(error_code& __ec)
2010 { __pop(&__ec); }
2011
2012 _LIBCPP_INLINE_VISIBILITY
2013 bool recursion_pending() const
2014 { return __rec_; }
2015
2016 _LIBCPP_INLINE_VISIBILITY
2017 void disable_recursion_pending()
2018 { __rec_ = false; }
2019
2020private:
2021 recursive_directory_iterator(const path& __p, directory_options __opt,
2022 error_code *__ec);
2023
2024 _LIBCPP_FUNC_VIS
2025 const directory_entry& __deref() const;
2026
2027 _LIBCPP_FUNC_VIS
2028 bool __try_recursion(error_code* __ec);
2029
2030 _LIBCPP_FUNC_VIS
2031 void __advance(error_code* __ec=nullptr);
2032
2033 _LIBCPP_FUNC_VIS
2034 recursive_directory_iterator& __increment(error_code *__ec=nullptr);
2035
2036 _LIBCPP_FUNC_VIS
2037 void __pop(error_code* __ec=nullptr);
2038
2039 friend bool operator==(const recursive_directory_iterator&,
2040 const recursive_directory_iterator&) _NOEXCEPT;
2041
2042 struct __shared_imp;
2043 shared_ptr<__shared_imp> __imp_;
2044 bool __rec_;
2045}; // class recursive_directory_iterator
2046
2047
2048_LIBCPP_INLINE_VISIBILITY
2049inline bool operator==(const recursive_directory_iterator& __lhs,
2050 const recursive_directory_iterator& __rhs) _NOEXCEPT
2051{
2052 return __lhs.__imp_ == __rhs.__imp_;
2053}
2054
2055_LIBCPP_INLINE_VISIBILITY
2056inline bool operator!=(const recursive_directory_iterator& __lhs,
2057 const recursive_directory_iterator& __rhs) _NOEXCEPT
2058{
2059 return !(__lhs == __rhs);
2060}
2061// enable recursive_directory_iterator range-based for statements
2062inline _LIBCPP_INLINE_VISIBILITY
2063recursive_directory_iterator begin(recursive_directory_iterator __iter) _NOEXCEPT {
2064 return __iter;
2065}
2066
2067inline _LIBCPP_INLINE_VISIBILITY
2068recursive_directory_iterator end(const recursive_directory_iterator&) _NOEXCEPT {
2069 return recursive_directory_iterator();
2070}
2071
2072_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
2073
2074#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM