blob: fa2face130f48c84cd42725a9f5a95b536afbc29 [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};
Eric Fiselier113315b2016-08-28 21:26:01 +0000456template <class _Tp> struct __can_convert_char<const _Tp>
457 : public __can_convert_char<_Tp> {
458};
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000459template <> struct __can_convert_char<char> {
460 static const bool value = true;
461 using __char_type = char;
462};
463template <> struct __can_convert_char<wchar_t> {
464 static const bool value = true;
465 using __char_type = wchar_t;
466};
467template <> struct __can_convert_char<char16_t> {
468 static const bool value = true;
469 using __char_type = char16_t;
470};
471template <> struct __can_convert_char<char32_t> {
472 static const bool value = true;
473 using __char_type = char32_t;
474};
475
476template <class _ECharT>
477typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
478__is_separator(_ECharT __e) {
479 return __e == _ECharT('/');
480};
481
482struct _NullSentinal {};
483
484template <class _Tp>
485using _Void = void;
486
487template <class _Tp, class = void>
488struct __is_pathable_string : public false_type {};
489
490template <class _ECharT, class _Traits, class _Alloc>
491struct __is_pathable_string<basic_string<_ECharT, _Traits, _Alloc>,
492 _Void<typename __can_convert_char<_ECharT>::__char_type>>
493: public __can_convert_char<_ECharT>
494{
495 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
496 using _Base = __can_convert_char<_ECharT>;
497 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
498 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
499 static _ECharT __first_or_null(_Str const& __s) {
500 return __s.empty() ? _ECharT{} : __s[0];
501 }
502};
503
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000504
505template <class _ECharT, class _Traits>
506struct __is_pathable_string<basic_string_view<_ECharT, _Traits>,
507 _Void<typename __can_convert_char<_ECharT>::__char_type>>
508: public __can_convert_char<_ECharT>
509{
510 using _Str = basic_string_view<_ECharT, _Traits>;
511 using _Base = __can_convert_char<_ECharT>;
512 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
513 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
514 static _ECharT __first_or_null(_Str const& __s) {
515 return __s.empty() ? _ECharT{} : __s[0];
516 }
517};
518
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000519template <class _Source,
520 class _DS = typename decay<_Source>::type,
521 class _UnqualPtrType = typename remove_const<
522 typename remove_pointer<_DS>::type>::type,
523 bool _IsCharPtr = is_pointer<_DS>::value &&
524 __can_convert_char<_UnqualPtrType>::value
525 >
526struct __is_pathable_char_array : false_type {};
527
528template <class _Source, class _ECharT, class _UPtr>
529struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
530 : __can_convert_char<typename remove_const<_ECharT>::type>
531{
532 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
533
534 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
535 static _ECharT const* __range_end(const _ECharT* __b)
536 {
537 using _Iter = const _ECharT*;
538 const _ECharT __sentinal = _ECharT{};
539 _Iter __e = __b;
540 for (; *__e != __sentinal; ++__e)
541 ;
542 return __e;
543 }
544
545 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
546};
547
548template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value, class = void>
549struct __is_pathable_iter : false_type {};
550
551template <class _Iter>
552struct __is_pathable_iter<_Iter, true,
553 _Void<typename __can_convert_char<typename iterator_traits<_Iter>::value_type>::__char_type>>
554 : __can_convert_char<typename iterator_traits<_Iter>::value_type>
555{
556 using _ECharT = typename iterator_traits<_Iter>::value_type;
557 using _Base = __can_convert_char<_ECharT>;
558
559 static _Iter __range_begin(_Iter __b) { return __b; }
560 static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; }
561
562 static _ECharT __first_or_null(_Iter __b) { return *__b; }
563};
564
565template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
566 bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
567 bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value
568 >
569struct __is_pathable : false_type {
570 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
571};
572
573template <class _Tp>
574struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
575
576
577template <class _Tp>
578struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {};
579
580
581template <class _Tp>
582struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
583
584
585template <class _ECharT>
586struct _PathCVT {
587 static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible");
588
589 typedef __narrow_to_utf8<sizeof(_ECharT)*__CHAR_BIT__> _Narrower;
590
591 static void __append_range(string& __dest, _ECharT const* __b, _ECharT const* __e) {
592 _Narrower()(back_inserter(__dest), __b, __e);
593 }
594
595 template <class _Iter>
596 static void __append_range(string& __dest, _Iter __b, _Iter __e) {
597 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
598 if (__b == __e) return;
599 basic_string<_ECharT> __tmp(__b, __e);
600 _Narrower()(back_inserter(__dest), __tmp.data(),
601 __tmp.data() + __tmp.length());
602 }
603
604 template <class _Iter>
605 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
606 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
607 const _ECharT __sentinal = _ECharT{};
608 if (*__b == __sentinal) return;
609 basic_string<_ECharT> __tmp;
610 for (; *__b != __sentinal; ++__b)
611 __tmp.push_back(*__b);
612 _Narrower()(back_inserter(__dest), __tmp.data(),
613 __tmp.data() + __tmp.length());
614 }
615
616 template <class _Source>
617 static void __append_source(string& __dest, _Source const& __s)
618 {
619 using _Traits = __is_pathable<_Source>;
620 __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
621 }
622};
623
624template <>
625struct _PathCVT<char> {
626 template <class _Iter>
627 static void __append_range(string& __dest, _Iter __b, _Iter __e) {
628 for (; __b != __e; ++__b)
629 __dest.push_back(*__b);
630 }
631
632 template <class _Iter>
633 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
634 const char __sentinal = char{};
635 for (; *__b != __sentinal; ++__b)
636 __dest.push_back(*__b);
637 }
638
639 template <class _Source>
640 static void __append_source(string& __dest, _Source const& __s)
641 {
642 using _Traits = __is_pathable<_Source>;
643 __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
644 }
645};
646
647
648class _LIBCPP_TYPE_VIS path
649{
650 template <class _SourceOrIter, class _Tp = path&>
651 using _EnableIfPathable = typename
652 enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
653
654 template <class _Tp>
655 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
656
657 template <class _Tp>
658 using _SourceCVT = _PathCVT<_SourceChar<_Tp>>;
659
660public:
661 typedef char value_type;
662 typedef basic_string<value_type> string_type;
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000663 typedef _VSTD::string_view __string_view;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000664 static _LIBCPP_CONSTEXPR value_type preferred_separator = '/';
665
666 // constructors and destructor
667 _LIBCPP_INLINE_VISIBILITY path() _NOEXCEPT {}
668 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
669 _LIBCPP_INLINE_VISIBILITY path(path&& __p) _NOEXCEPT : __pn_(_VSTD::move(__p.__pn_)) {}
670
671 _LIBCPP_INLINE_VISIBILITY
672 path(string_type&& __s) _NOEXCEPT : __pn_(_VSTD::move(__s)) {}
673
674 template <
675 class _Source,
676 class = _EnableIfPathable<_Source, void>
677 >
678 path(const _Source& __src) {
679 _SourceCVT<_Source>::__append_source(__pn_, __src);
680 }
681
682 template <class _InputIt>
683 path(_InputIt __first, _InputIt __last) {
684 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
685 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
686 }
687
688 // TODO Implement locale conversions.
689 template <class _Source,
690 class = _EnableIfPathable<_Source, void>
691 >
692 path(const _Source& __src, const locale& __loc);
693 template <class _InputIt>
694 path(_InputIt __first, _InputIt _last, const locale& __loc);
695
696 _LIBCPP_INLINE_VISIBILITY
697 ~path() = default;
698
699 // assignments
700 _LIBCPP_INLINE_VISIBILITY
701 path& operator=(const path& __p) {
702 __pn_ = __p.__pn_;
703 return *this;
704 }
705
706 _LIBCPP_INLINE_VISIBILITY
707 path& operator=(path&& __p) _NOEXCEPT {
708 __pn_ = _VSTD::move(__p.__pn_);
709 return *this;
710 }
711
712 _LIBCPP_INLINE_VISIBILITY
713 path& operator=(string_type&& __s) _NOEXCEPT {
714 __pn_ = _VSTD::move(__s);
715 return *this;
716 }
717
718 _LIBCPP_INLINE_VISIBILITY
719 path& assign(string_type&& __s) _NOEXCEPT {
720 __pn_ = _VSTD::move(__s);
721 return *this;
722 }
723
724 template <class _Source>
725 _LIBCPP_INLINE_VISIBILITY
726 _EnableIfPathable<_Source>
727 operator=(const _Source& __src)
728 { return this->assign(__src); }
729
730
731 template <class _Source>
732 _EnableIfPathable<_Source>
733 assign(const _Source& __src) {
734 __pn_.clear();
735 _SourceCVT<_Source>::__append_source(__pn_, __src);
736 return *this;
737 }
738
739 template <class _InputIt>
740 path& assign(_InputIt __first, _InputIt __last) {
741 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
742 __pn_.clear();
743 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
744 return *this;
745 }
746
747private:
748 template <class _ECharT>
749 void __append_sep_if_needed(_ECharT __first_or_null) {
750 const _ECharT __null_val = {};
751 bool __append_sep = !empty() &&
752 !__is_separator(__pn_.back()) &&
753 __first_or_null != __null_val && // non-empty
754 !__is_separator(__first_or_null);
755 if (__append_sep)
756 __pn_ += preferred_separator;
757 }
758
759public:
760 // appends
761 path& operator/=(const path& __p) {
762 __append_sep_if_needed(__p.empty() ? char{} : __p.__pn_[0]);
763 __pn_ += __p.native();
764 return *this;
765 }
766
767 template <class _Source>
768 _LIBCPP_INLINE_VISIBILITY
769 _EnableIfPathable<_Source>
770 operator/=(const _Source& __src) {
771 return this->append(__src);
772 }
773
774 template <class _Source>
775 _EnableIfPathable<_Source>
776 append(const _Source& __src) {
777 using _Traits = __is_pathable<_Source>;
778 using _CVT = _PathCVT<_SourceChar<_Source>>;
779 __append_sep_if_needed(_Traits::__first_or_null(__src));
780 _CVT::__append_source(__pn_, __src);
781 return *this;
782 }
783
784 template <class _InputIt>
785 path& append(_InputIt __first, _InputIt __last) {
786 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
787 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
788 using _CVT = _PathCVT<_ItVal>;
789 if (__first != __last) {
790 __append_sep_if_needed(*__first);
791 _CVT::__append_range(__pn_, __first, __last);
792 }
793 return *this;
794 }
795
796 // concatenation
797 _LIBCPP_INLINE_VISIBILITY
798 path& operator+=(const path& __x) {
799 __pn_ += __x.__pn_;
800 return *this;
801 }
802
803 _LIBCPP_INLINE_VISIBILITY
804 path& operator+=(const string_type& __x) {
805 __pn_ += __x;
806 return *this;
807 }
808
809 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000810 path& operator+=(__string_view __x) {
811 __pn_ += __x;
812 return *this;
813 }
814
815 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000816 path& operator+=(const value_type* __x) {
817 __pn_ += __x;
818 return *this;
819 }
820
821 _LIBCPP_INLINE_VISIBILITY
822 path& operator+=(value_type __x) {
823 __pn_ += __x;
824 return *this;
825 }
826
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000827 template <class _ECharT>
828 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
829 operator+=(_ECharT __x)
830 {
831 basic_string<_ECharT> __tmp;
832 __tmp += __x;
833 _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
834 return *this;
835 }
836
837 template <class _Source>
838 _EnableIfPathable<_Source>
839 operator+=(const _Source& __x) {
840 return this->concat(__x);
841 }
842
843 template <class _Source>
844 _EnableIfPathable<_Source>
845 concat(const _Source& __x) {
846 _SourceCVT<_Source>::__append_source(__pn_, __x);
847 return *this;
848 }
849
850 template <class _InputIt>
851 path& concat(_InputIt __first, _InputIt __last) {
852 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
853 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
854 return *this;
855 }
856
857 // modifiers
858 _LIBCPP_INLINE_VISIBILITY
859 void clear() _NOEXCEPT {
860 __pn_.clear();
861 }
862
863 path& make_preferred() { return *this; }
864 path& remove_filename() { return *this = parent_path(); }
865
866 path& replace_filename(const path& __replacement) {
867 remove_filename();
868 return (*this /= __replacement);
869 }
870
871 path& replace_extension(const path& __replacement = path());
872
873 _LIBCPP_INLINE_VISIBILITY
874 void swap(path& __rhs) _NOEXCEPT {
875 __pn_.swap(__rhs.__pn_);
876 }
877
878 // native format observers
879 _LIBCPP_INLINE_VISIBILITY
880 const string_type& native() const _NOEXCEPT {
881 return __pn_;
882 }
883
884 _LIBCPP_INLINE_VISIBILITY
885 const value_type* c_str() const _NOEXCEPT { return __pn_.c_str(); }
886
887 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
888
889 template <class _ECharT, class _Traits = char_traits<_ECharT>,
890 class _Allocator = allocator<_ECharT> >
891 basic_string<_ECharT, _Traits, _Allocator>
892 string(const _Allocator& __a = _Allocator()) const {
893 using _CVT = __widen_from_utf8<sizeof(_ECharT)*__CHAR_BIT__>;
894 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
895 _Str __s(__a);
896 __s.reserve(__pn_.size());
897 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
898 return __s;
899 }
900
901 _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
902 _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const { return string<wchar_t>(); }
903 _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
904 _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { return string<char16_t>(); }
905 _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { return string<char32_t>(); }
906
907 // generic format observers
908 template <class _ECharT, class _Traits = char_traits<_ECharT>,
909 class _Allocator = allocator<_ECharT>
910 >
911 basic_string<_ECharT, _Traits, _Allocator>
912 generic_string(const _Allocator& __a = _Allocator()) const {
913 return string<_ECharT, _Traits, _Allocator>(__a);
914 }
915
916 std::string generic_string() const { return __pn_; }
917 std::wstring generic_wstring() const { return string<wchar_t>(); }
918 std::string generic_u8string() const { return __pn_; }
919 std::u16string generic_u16string() const { return string<char16_t>(); }
920 std::u32string generic_u32string() const { return string<char32_t>(); }
921
922private:
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000923 _LIBCPP_FUNC_VIS int __compare(__string_view) const;
924 _LIBCPP_FUNC_VIS __string_view __root_name() const;
925 _LIBCPP_FUNC_VIS __string_view __root_directory() const;
926 _LIBCPP_FUNC_VIS __string_view __relative_path() const;
927 _LIBCPP_FUNC_VIS __string_view __parent_path() const;
928 _LIBCPP_FUNC_VIS __string_view __filename() const;
929 _LIBCPP_FUNC_VIS __string_view __stem() const;
930 _LIBCPP_FUNC_VIS __string_view __extension() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000931
932public:
933 // compare
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000934 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const _NOEXCEPT { return __compare(__p.__pn_);}
935 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); }
936 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000937 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { return __compare(__s); }
938
939 // decomposition
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000940 _LIBCPP_INLINE_VISIBILITY path root_name() const { return string_type(__root_name()); }
941 _LIBCPP_INLINE_VISIBILITY path root_directory() const { return string_type(__root_directory()); }
942 _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(string_type(__root_directory())); }
943 _LIBCPP_INLINE_VISIBILITY path relative_path() const { return string_type(__relative_path()); }
944 _LIBCPP_INLINE_VISIBILITY path parent_path() const { return string_type(__parent_path()); }
945 _LIBCPP_INLINE_VISIBILITY path filename() const { return string_type(__filename()); }
946 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem());}
947 _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000948
949 // query
950 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT { return __pn_.empty(); }
951
952 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); }
953 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); }
954 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !(__root_name().empty() && __root_directory().empty()); }
955 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { return !__relative_path().empty(); }
956 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { return !__parent_path().empty(); }
957 _LIBCPP_INLINE_VISIBILITY bool has_filename() const { return !__filename().empty(); }
958 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
959 _LIBCPP_INLINE_VISIBILITY bool has_extension() const { return !__extension().empty(); }
960
961 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { return has_root_directory(); }
962 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
963
964 // iterators
965 class _LIBCPP_TYPE_VIS iterator;
966 typedef iterator const_iterator;
967
968 _LIBCPP_FUNC_VIS iterator begin() const;
969 _LIBCPP_FUNC_VIS iterator end() const;
970
971private:
972 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000973 path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; }
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000974 string_type __pn_;
975};
976
977inline _LIBCPP_ALWAYS_INLINE
978void swap(path& __lhs, path& __rhs) _NOEXCEPT {
979 __lhs.swap(__rhs);
980}
981
982_LIBCPP_FUNC_VIS
983size_t hash_value(const path& __p) _NOEXCEPT;
984
985inline _LIBCPP_INLINE_VISIBILITY
986bool operator==(const path& __lhs, const path& __rhs) _NOEXCEPT
987{ return __lhs.compare(__rhs) == 0; }
988
989inline _LIBCPP_INLINE_VISIBILITY
990bool operator!=(const path& __lhs, const path& __rhs) _NOEXCEPT
991{ return __lhs.compare(__rhs) != 0; }
992
993inline _LIBCPP_INLINE_VISIBILITY
994bool operator<(const path& __lhs, const path& __rhs) _NOEXCEPT
995{ return __lhs.compare(__rhs) < 0; }
996
997inline _LIBCPP_INLINE_VISIBILITY
998bool operator<=(const path& __lhs, const path& __rhs) _NOEXCEPT
999{ return __lhs.compare(__rhs) <= 0; }
1000
1001inline _LIBCPP_INLINE_VISIBILITY
1002bool operator>(const path& __lhs, const path& __rhs) _NOEXCEPT
1003{ return __lhs.compare(__rhs) > 0; }
1004
1005inline _LIBCPP_INLINE_VISIBILITY
1006bool operator>=(const path& __lhs, const path& __rhs) _NOEXCEPT
1007{ return __lhs.compare(__rhs) >= 0; }
1008
1009inline _LIBCPP_INLINE_VISIBILITY
1010path operator/(const path& __lhs, const path& __rhs) {
1011 return path(__lhs) /= __rhs;
1012}
1013
1014template <class _CharT, class _Traits>
1015_LIBCPP_INLINE_VISIBILITY
1016typename enable_if<is_same<_CharT, char>::value &&
1017 is_same<_Traits, char_traits<char>>::value,
1018 basic_ostream<_CharT, _Traits>&
1019>::type
1020operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1021 __os << std::__quoted(__p.native());
1022 return __os;
1023}
1024
1025template <class _CharT, class _Traits>
1026_LIBCPP_INLINE_VISIBILITY
1027typename enable_if<!is_same<_CharT, char>::value ||
1028 !is_same<_Traits, char_traits<char>>::value,
1029 basic_ostream<_CharT, _Traits>&
1030>::type
1031operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1032 __os << std::__quoted(__p.string<_CharT, _Traits>());
1033 return __os;
1034}
1035
1036template <class _CharT, class _Traits>
1037_LIBCPP_INLINE_VISIBILITY
1038basic_istream<_CharT, _Traits>&
1039operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
1040{
1041 basic_string<_CharT, _Traits> __tmp;
1042 __is >> __quoted(__tmp);
1043 __p = __tmp;
1044 return __is;
1045}
1046
1047template <class _Source>
1048_LIBCPP_INLINE_VISIBILITY
1049typename enable_if<__is_pathable<_Source>::value, path>::type
1050u8path(const _Source& __s){
1051 static_assert(is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1052 "u8path(Source const&) requires Source have a character type of type 'char'");
1053 return path(__s);
1054}
1055
1056template <class _InputIt>
1057_LIBCPP_INLINE_VISIBILITY
1058typename enable_if<__is_pathable<_InputIt>::value, path>::type
1059u8path(_InputIt __f, _InputIt __l) {
1060 static_assert(is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1061 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1062 return path(__f, __l);
1063}
1064
1065class _LIBCPP_TYPE_VIS path::iterator
1066{
1067public:
1068 typedef bidirectional_iterator_tag iterator_category;
1069 typedef path value_type;
1070 typedef std::ptrdiff_t difference_type;
1071 typedef const path* pointer;
1072 typedef const path& reference;
1073public:
1074 _LIBCPP_INLINE_VISIBILITY
1075 iterator() : __elem_(), __path_ptr_(nullptr), __pos_(0) {}
1076
1077 iterator(const iterator&) = default;
1078 ~iterator() = default;
1079
1080 iterator& operator=(const iterator&) = default;
1081
1082 _LIBCPP_INLINE_VISIBILITY
1083 reference operator*() const {
1084 return __elem_;
1085 }
1086
1087 _LIBCPP_INLINE_VISIBILITY
1088 pointer operator->() const {
1089 return &__elem_;
1090 }
1091
1092 _LIBCPP_INLINE_VISIBILITY
1093 iterator& operator++() {
1094 return __increment();
1095 }
1096
1097 _LIBCPP_INLINE_VISIBILITY
1098 iterator operator++(int) {
1099 iterator __it(*this);
1100 this->operator++();
1101 return __it;
1102 }
1103
1104 _LIBCPP_INLINE_VISIBILITY
1105 iterator& operator--() {
1106 return __decrement();
1107 }
1108
1109 _LIBCPP_INLINE_VISIBILITY
1110 iterator operator--(int) {
1111 iterator __it(*this);
1112 this->operator--();
1113 return __it;
1114 }
1115
1116private:
1117 friend class path;
1118 friend bool operator==(const iterator&, const iterator&);
1119
1120 _LIBCPP_FUNC_VIS iterator& __increment();
1121 _LIBCPP_FUNC_VIS iterator& __decrement();
1122
1123 path __elem_;
1124 const path* __path_ptr_;
1125 size_t __pos_;
1126};
1127
1128inline _LIBCPP_INLINE_VISIBILITY
1129bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) {
1130 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
1131 __lhs.__pos_ == __rhs.__pos_;
1132}
1133
1134inline _LIBCPP_INLINE_VISIBILITY
1135bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) {
1136 return !(__lhs == __rhs);
1137}
1138
1139class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error
1140{
1141public:
1142 _LIBCPP_INLINE_VISIBILITY
1143 filesystem_error(const string& __what, error_code __ec)
1144 : system_error(__ec, __what),
1145 __paths_(make_shared<_Storage>(path(), path()))
1146 {}
1147
1148 _LIBCPP_INLINE_VISIBILITY
1149 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1150 : system_error(__ec, __what),
1151 __paths_(make_shared<_Storage>(__p1, path()))
1152 {}
1153
1154 _LIBCPP_INLINE_VISIBILITY
1155 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1156 error_code __ec)
1157 : system_error(__ec, __what),
1158 __paths_(make_shared<_Storage>(__p1, __p2))
1159 {}
1160
1161 _LIBCPP_INLINE_VISIBILITY
1162 const path& path1() const _NOEXCEPT {
1163 return __paths_->first;
1164 }
1165
1166 _LIBCPP_INLINE_VISIBILITY
1167 const path& path2() const _NOEXCEPT {
1168 return __paths_->second;
1169 }
1170
1171 _LIBCPP_FUNC_VIS
1172 ~filesystem_error() override; // key function
1173
1174 // TODO(ericwf): Create a custom error message.
1175 //const char* what() const _NOEXCEPT;
1176
1177private:
1178 typedef pair<path, path> _Storage;
1179 shared_ptr<_Storage> __paths_;
1180};
1181
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001182template <class... _Args>
1183_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
1184void __throw_filesystem_error(_Args && ...__args)
1185{
1186#ifndef _LIBCPP_NO_EXCEPTIONS
1187 throw filesystem_error(std::forward<_Args>(__args)...);
1188#else
1189 _VSTD::abort();
1190#endif
1191}
1192
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001193// operational functions
1194
1195_LIBCPP_FUNC_VIS
1196path __canonical(const path&, const path&, error_code *__ec=nullptr);
1197_LIBCPP_FUNC_VIS
1198void __copy(const path& __from, const path& __to, copy_options __opt,
1199 error_code *__ec=nullptr);
1200_LIBCPP_FUNC_VIS
1201bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1202 error_code *__ec=nullptr);
1203_LIBCPP_FUNC_VIS
1204void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1205 error_code *__ec=nullptr);
1206_LIBCPP_FUNC_VIS
1207bool __create_directories(const path& p, error_code *ec=nullptr);
1208_LIBCPP_FUNC_VIS
1209bool __create_directory(const path& p, error_code *ec=nullptr);
1210_LIBCPP_FUNC_VIS
1211bool __create_directory(const path& p, const path & attributes,
1212 error_code *ec=nullptr);
1213_LIBCPP_FUNC_VIS
1214void __create_directory_symlink(const path& __to, const path& __new_symlink,
1215 error_code *__ec=nullptr);
1216_LIBCPP_FUNC_VIS
1217void __create_hard_link(const path& __to, const path& __new_hard_link,
1218 error_code *__ec=nullptr);
1219_LIBCPP_FUNC_VIS
1220void __create_symlink(const path& __to, const path& __new_symlink,
1221 error_code *__ec=nullptr);
1222_LIBCPP_FUNC_VIS
1223path __current_path(error_code *__ec=nullptr);
1224_LIBCPP_FUNC_VIS
1225void __current_path(const path&, error_code *__ec=nullptr);
1226_LIBCPP_FUNC_VIS
1227bool __equivalent(const path&, const path&, error_code *__ec=nullptr);
1228_LIBCPP_FUNC_VIS
1229uintmax_t __file_size(const path&, error_code *__ec=nullptr);
1230_LIBCPP_FUNC_VIS
1231uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr);
1232_LIBCPP_FUNC_VIS
1233bool __fs_is_empty(const path& p, error_code *ec=nullptr);
1234_LIBCPP_FUNC_VIS
1235file_time_type __last_write_time(const path& p, error_code *ec=nullptr);
1236_LIBCPP_FUNC_VIS
1237void __last_write_time(const path& p, file_time_type new_time,
1238 error_code *ec=nullptr);
1239_LIBCPP_FUNC_VIS
1240void __permissions(const path& p, perms prms, error_code *ec=nullptr);
1241_LIBCPP_FUNC_VIS
1242path __read_symlink(const path& p, error_code *ec=nullptr);
1243_LIBCPP_FUNC_VIS
1244bool __remove(const path& p, error_code *ec=nullptr);
1245_LIBCPP_FUNC_VIS
1246uintmax_t __remove_all(const path& p, error_code *ec=nullptr);
1247_LIBCPP_FUNC_VIS
1248void __rename(const path& from, const path& to, error_code *ec=nullptr);
1249_LIBCPP_FUNC_VIS
1250void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr);
1251_LIBCPP_FUNC_VIS
1252space_info __space(const path&, error_code *__ec=nullptr);
1253_LIBCPP_FUNC_VIS
1254file_status __status(const path&, error_code *__ec=nullptr);
1255_LIBCPP_FUNC_VIS
1256file_status __symlink_status(const path&, error_code *__ec=nullptr);
1257_LIBCPP_FUNC_VIS
1258path __system_complete(const path&, error_code *__ec=nullptr);
1259_LIBCPP_FUNC_VIS
1260path __temp_directory_path(error_code *__ec=nullptr);
1261
1262inline _LIBCPP_INLINE_VISIBILITY
1263path current_path() {
1264 return __current_path();
1265}
1266
1267inline _LIBCPP_INLINE_VISIBILITY
1268path current_path(error_code& __ec) {
1269 return __current_path(&__ec);
1270}
1271
1272inline _LIBCPP_INLINE_VISIBILITY
1273void current_path(const path& __p) {
1274 __current_path(__p);
1275}
1276
1277inline _LIBCPP_INLINE_VISIBILITY
1278void current_path(const path& __p, error_code& __ec) _NOEXCEPT {
1279 __current_path(__p, &__ec);
1280}
1281
1282_LIBCPP_FUNC_VIS
1283path absolute(const path&, const path& __p2 = current_path());
1284
1285inline _LIBCPP_INLINE_VISIBILITY
1286path canonical(const path& __p, const path& __base = current_path()) {
1287 return __canonical(__p, __base);
1288}
1289
1290inline _LIBCPP_INLINE_VISIBILITY
1291path canonical(const path& __p, error_code& __ec) {
1292 path __base = __current_path(&__ec);
1293 if (__ec) return {};
1294 return __canonical(__p, __base, &__ec);
1295}
1296
1297inline _LIBCPP_INLINE_VISIBILITY
1298path canonical(const path& __p, const path& __base, error_code& __ec) {
1299 return __canonical(__p, __base, &__ec);
1300}
1301
1302inline _LIBCPP_INLINE_VISIBILITY
1303void copy(const path& __from, const path& __to) {
1304 __copy(__from, __to, copy_options::none);
1305}
1306
1307inline _LIBCPP_INLINE_VISIBILITY
1308void copy(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
1309 __copy(__from, __to, copy_options::none, &__ec);
1310}
1311
1312inline _LIBCPP_INLINE_VISIBILITY
1313void copy(const path& __from, const path& __to, copy_options __opt) {
1314 __copy(__from, __to, __opt);
1315}
1316
1317inline _LIBCPP_INLINE_VISIBILITY
1318void copy(const path& __from, const path& __to,
1319 copy_options __opt, error_code& __ec) _NOEXCEPT {
1320 __copy(__from, __to, __opt, &__ec);
1321}
1322
1323inline _LIBCPP_INLINE_VISIBILITY
1324bool copy_file(const path& __from, const path& __to) {
1325 return __copy_file(__from, __to, copy_options::none);
1326}
1327
1328inline _LIBCPP_INLINE_VISIBILITY
1329bool copy_file(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
1330 return __copy_file(__from, __to, copy_options::none, &__ec);
1331}
1332
1333inline _LIBCPP_INLINE_VISIBILITY
1334bool copy_file(const path& __from, const path& __to, copy_options __opt) {
1335 return __copy_file(__from, __to, __opt);
1336}
1337
1338inline _LIBCPP_INLINE_VISIBILITY
1339bool copy_file(const path& __from, const path& __to,
1340 copy_options __opt, error_code& __ec) _NOEXCEPT {
1341 return __copy_file(__from, __to, __opt, &__ec);
1342}
1343
1344inline _LIBCPP_INLINE_VISIBILITY
1345void copy_symlink(const path& __existing, const path& __new) {
1346 __copy_symlink(__existing, __new);
1347}
1348
1349inline _LIBCPP_INLINE_VISIBILITY
1350void copy_symlink(const path& __ext, const path& __new, error_code& __ec) _NOEXCEPT {
1351 __copy_symlink(__ext, __new, &__ec);
1352}
1353
1354inline _LIBCPP_INLINE_VISIBILITY
1355bool create_directories(const path& __p) {
1356 return __create_directories(__p);
1357}
1358
1359inline _LIBCPP_INLINE_VISIBILITY
1360bool create_directories(const path& __p, error_code& __ec) _NOEXCEPT {
1361 return __create_directories(__p, &__ec);
1362}
1363
1364inline _LIBCPP_INLINE_VISIBILITY
1365bool create_directory(const path& __p) {
1366 return __create_directory(__p);
1367}
1368
1369inline _LIBCPP_INLINE_VISIBILITY
1370bool create_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1371 return __create_directory(__p, &__ec);
1372}
1373
1374inline _LIBCPP_INLINE_VISIBILITY
1375bool create_directory(const path& __p, const path& __attrs) {
1376 return __create_directory(__p, __attrs);
1377}
1378
1379inline _LIBCPP_INLINE_VISIBILITY
1380bool create_directory(const path& __p, const path& __attrs, error_code& __ec) _NOEXCEPT {
1381 return __create_directory(__p, __attrs, &__ec);
1382}
1383
1384inline _LIBCPP_INLINE_VISIBILITY
1385void create_directory_symlink(const path& __to, const path& __new) {
1386 __create_directory_symlink(__to, __new);
1387}
1388
1389inline _LIBCPP_INLINE_VISIBILITY
1390void create_directory_symlink(const path& __to, const path& __new,
1391 error_code& __ec) _NOEXCEPT {
1392 __create_directory_symlink(__to, __new, &__ec);
1393}
1394
1395inline _LIBCPP_INLINE_VISIBILITY
1396void create_hard_link(const path& __to, const path& __new) {
1397 __create_hard_link(__to, __new);
1398}
1399
1400inline _LIBCPP_INLINE_VISIBILITY
1401void create_hard_link(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
1402 __create_hard_link(__to, __new, &__ec);
1403}
1404
1405inline _LIBCPP_INLINE_VISIBILITY
1406void create_symlink(const path& __to, const path& __new) {
1407 __create_symlink(__to, __new);
1408}
1409
1410inline _LIBCPP_INLINE_VISIBILITY
1411void create_symlink(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
1412 return __create_symlink(__to, __new, &__ec);
1413}
1414
1415inline _LIBCPP_INLINE_VISIBILITY
1416bool status_known(file_status __s) _NOEXCEPT {
1417 return __s.type() != file_type::none;
1418}
1419
1420inline _LIBCPP_INLINE_VISIBILITY
1421bool exists(file_status __s) _NOEXCEPT {
1422 return status_known(__s) && __s.type() != file_type::not_found;
1423}
1424
1425inline _LIBCPP_INLINE_VISIBILITY
1426bool exists(const path& __p) {
1427 return exists(__status(__p));
1428}
1429
1430inline _LIBCPP_INLINE_VISIBILITY
1431bool exists(const path& __p, error_code& __ec) _NOEXCEPT {
Eric Fiselier756a6bd2016-06-21 22:11:16 +00001432 auto __s = __status(__p, &__ec);
1433 if (status_known(__s)) __ec.clear();
1434 return exists(__s);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001435}
1436
1437inline _LIBCPP_INLINE_VISIBILITY
1438bool equivalent(const path& __p1, const path& __p2) {
1439 return __equivalent(__p1, __p2);
1440}
1441
1442inline _LIBCPP_INLINE_VISIBILITY
1443bool equivalent(const path& __p1, const path& __p2, error_code& __ec) _NOEXCEPT {
1444 return __equivalent(__p1, __p2, &__ec);
1445}
1446
1447inline _LIBCPP_INLINE_VISIBILITY
1448uintmax_t file_size(const path& __p) {
1449 return __file_size(__p);
1450}
1451
1452inline _LIBCPP_INLINE_VISIBILITY
1453uintmax_t file_size(const path& __p, error_code& __ec) _NOEXCEPT {
1454 return __file_size(__p, &__ec);
1455}
1456
1457inline _LIBCPP_INLINE_VISIBILITY
1458uintmax_t hard_link_count(const path& __p) {
1459 return __hard_link_count(__p);
1460}
1461
1462inline _LIBCPP_INLINE_VISIBILITY
1463uintmax_t hard_link_count(const path& __p, error_code& __ec) _NOEXCEPT {
1464 return __hard_link_count(__p, &__ec);
1465}
1466
1467inline _LIBCPP_INLINE_VISIBILITY
1468bool is_block_file(file_status __s) _NOEXCEPT {
1469 return __s.type() == file_type::block;
1470}
1471
1472inline _LIBCPP_INLINE_VISIBILITY
1473bool is_block_file(const path& __p) {
1474 return is_block_file(__status(__p));
1475}
1476
1477inline _LIBCPP_INLINE_VISIBILITY
1478bool is_block_file(const path& __p, error_code& __ec) _NOEXCEPT {
1479 return is_block_file(__status(__p, &__ec));
1480}
1481
1482inline _LIBCPP_INLINE_VISIBILITY
1483bool is_character_file(file_status __s) _NOEXCEPT {
1484 return __s.type() == file_type::character;
1485}
1486
1487inline _LIBCPP_INLINE_VISIBILITY
1488bool is_character_file(const path& __p) {
1489 return is_character_file(__status(__p));
1490}
1491
1492inline _LIBCPP_INLINE_VISIBILITY
1493bool is_character_file(const path& __p, error_code& __ec) _NOEXCEPT {
1494 return is_character_file(__status(__p, &__ec));
1495}
1496
1497inline _LIBCPP_INLINE_VISIBILITY
1498bool is_directory(file_status __s) _NOEXCEPT {
1499 return __s.type() == file_type::directory;
1500}
1501
1502inline _LIBCPP_INLINE_VISIBILITY
1503bool is_directory(const path& __p) {
1504 return is_directory(__status(__p));
1505}
1506
1507inline _LIBCPP_INLINE_VISIBILITY
1508bool is_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1509 return is_directory(__status(__p, &__ec));
1510}
1511
1512inline _LIBCPP_INLINE_VISIBILITY
1513bool is_empty(const path& __p) {
1514 return __fs_is_empty(__p);
1515}
1516
1517inline _LIBCPP_INLINE_VISIBILITY
1518bool is_empty(const path& __p, error_code& __ec) _NOEXCEPT {
1519 return __fs_is_empty(__p, &__ec);
1520}
1521
1522inline _LIBCPP_INLINE_VISIBILITY
1523bool is_fifo(file_status __s) _NOEXCEPT {
1524 return __s.type() == file_type::fifo;
1525}
1526inline _LIBCPP_INLINE_VISIBILITY
1527bool is_fifo(const path& __p) {
1528 return is_fifo(__status(__p));
1529}
1530
1531inline _LIBCPP_INLINE_VISIBILITY
1532bool is_fifo(const path& __p, error_code& __ec) _NOEXCEPT {
1533 return is_fifo(__status(__p, &__ec));
1534}
1535
1536inline _LIBCPP_INLINE_VISIBILITY
1537bool is_regular_file(file_status __s) _NOEXCEPT {
1538 return __s.type() == file_type::regular;
1539}
1540
1541inline _LIBCPP_INLINE_VISIBILITY
1542bool is_regular_file(const path& __p) {
1543 return is_regular_file(__status(__p));
1544}
1545
1546inline _LIBCPP_INLINE_VISIBILITY
1547bool is_regular_file(const path& __p, error_code& __ec) _NOEXCEPT {
1548 return is_regular_file(__status(__p, &__ec));
1549}
1550
1551inline _LIBCPP_INLINE_VISIBILITY
1552bool is_socket(file_status __s) _NOEXCEPT {
1553 return __s.type() == file_type::socket;
1554}
1555
1556inline _LIBCPP_INLINE_VISIBILITY
1557bool is_socket(const path& __p) {
1558 return is_socket(__status(__p));
1559}
1560
1561inline _LIBCPP_INLINE_VISIBILITY
1562bool is_socket(const path& __p, error_code& __ec) _NOEXCEPT {
1563 return is_socket(__status(__p, &__ec));
1564}
1565
1566inline _LIBCPP_INLINE_VISIBILITY
1567bool is_symlink(file_status __s) _NOEXCEPT {
1568 return __s.type() == file_type::symlink;
1569}
1570
1571inline _LIBCPP_INLINE_VISIBILITY
1572bool is_symlink(const path& __p) {
1573 return is_symlink(__symlink_status(__p));
1574}
1575
1576inline _LIBCPP_INLINE_VISIBILITY
1577bool is_symlink(const path& __p, error_code& __ec) _NOEXCEPT {
1578 return is_symlink(__symlink_status(__p, &__ec));
1579}
1580
1581inline _LIBCPP_INLINE_VISIBILITY
1582bool is_other(file_status __s) _NOEXCEPT {
1583 return exists(__s)
1584 && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s);
1585}
1586
1587inline _LIBCPP_INLINE_VISIBILITY
1588bool is_other(const path& __p) {
1589 return is_other(__status(__p));
1590}
1591
1592inline _LIBCPP_INLINE_VISIBILITY
1593bool is_other(const path& __p, error_code& __ec) _NOEXCEPT {
1594 return is_other(__status(__p, &__ec));
1595}
1596
1597inline _LIBCPP_INLINE_VISIBILITY
1598file_time_type last_write_time(const path& __p) {
1599 return __last_write_time(__p);
1600}
1601
1602inline _LIBCPP_INLINE_VISIBILITY
1603file_time_type last_write_time(const path& __p, error_code& __ec) _NOEXCEPT {
1604 return __last_write_time(__p, &__ec);
1605}
1606
1607inline _LIBCPP_INLINE_VISIBILITY
1608void last_write_time(const path& __p, file_time_type __t) {
1609 __last_write_time(__p, __t);
1610}
1611
1612inline _LIBCPP_INLINE_VISIBILITY
1613void last_write_time(const path& __p, file_time_type __t, error_code& __ec) _NOEXCEPT {
1614 __last_write_time(__p, __t, &__ec);
1615}
1616
1617inline _LIBCPP_INLINE_VISIBILITY
1618void permissions(const path& __p, perms __prms) {
1619 __permissions(__p, __prms);
1620}
1621
1622inline _LIBCPP_INLINE_VISIBILITY
1623void permissions(const path& __p, perms __prms, error_code& __ec) {
1624 __permissions(__p, __prms, &__ec);
1625}
1626
1627inline _LIBCPP_INLINE_VISIBILITY
1628path read_symlink(const path& __p) {
1629 return __read_symlink(__p);
1630}
1631
1632inline _LIBCPP_INLINE_VISIBILITY
1633path read_symlink(const path& __p, error_code& __ec) {
1634 return __read_symlink(__p, &__ec);
1635}
1636
1637inline _LIBCPP_INLINE_VISIBILITY
1638bool remove(const path& __p) {
1639 return __remove(__p);
1640}
1641
1642inline _LIBCPP_INLINE_VISIBILITY
1643bool remove(const path& __p, error_code& __ec) _NOEXCEPT {
1644 return __remove(__p, &__ec);
1645}
1646
1647inline _LIBCPP_INLINE_VISIBILITY
1648uintmax_t remove_all(const path& __p) {
1649 return __remove_all(__p);
1650}
1651
1652inline _LIBCPP_INLINE_VISIBILITY
1653uintmax_t remove_all(const path& __p, error_code& __ec) _NOEXCEPT {
1654 return __remove_all(__p, &__ec);
1655}
1656
1657inline _LIBCPP_INLINE_VISIBILITY
1658void rename(const path& __from, const path& __to) {
1659 return __rename(__from, __to);
1660}
1661
1662inline _LIBCPP_INLINE_VISIBILITY
1663void rename(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
1664 return __rename(__from, __to, &__ec);
1665}
1666
1667inline _LIBCPP_INLINE_VISIBILITY
1668void resize_file(const path& __p, uintmax_t __ns) {
1669 return __resize_file(__p, __ns);
1670}
1671
1672inline _LIBCPP_INLINE_VISIBILITY
1673void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) _NOEXCEPT {
1674 return __resize_file(__p, __ns, &__ec);
1675}
1676
1677inline _LIBCPP_INLINE_VISIBILITY
1678space_info space(const path& __p) {
1679 return __space(__p);
1680}
1681
1682inline _LIBCPP_INLINE_VISIBILITY
1683space_info space(const path& __p, error_code& __ec) _NOEXCEPT {
1684 return __space(__p, &__ec);
1685}
1686
1687inline _LIBCPP_INLINE_VISIBILITY
1688file_status status(const path& __p) {
1689 return __status(__p);
1690}
1691
1692inline _LIBCPP_INLINE_VISIBILITY
1693file_status status(const path& __p, error_code& __ec) _NOEXCEPT {
1694 return __status(__p, &__ec);
1695}
1696
1697inline _LIBCPP_INLINE_VISIBILITY
1698file_status symlink_status(const path& __p) {
1699 return __symlink_status(__p);
1700}
1701
1702inline _LIBCPP_INLINE_VISIBILITY
1703file_status symlink_status(const path& __p, error_code& __ec) _NOEXCEPT {
1704 return __symlink_status(__p, &__ec);
1705}
1706
1707inline _LIBCPP_INLINE_VISIBILITY
1708path system_complete(const path& __p) {
1709 return __system_complete(__p);
1710}
1711
1712inline _LIBCPP_INLINE_VISIBILITY
1713path system_complete(const path& __p, error_code& __ec) {
1714 return __system_complete(__p, &__ec);
1715}
1716
1717inline _LIBCPP_INLINE_VISIBILITY
1718path temp_directory_path() {
1719 return __temp_directory_path();
1720}
1721
1722inline _LIBCPP_INLINE_VISIBILITY
1723path temp_directory_path(error_code& __ec) {
1724 return __temp_directory_path(&__ec);
1725}
1726
1727
1728class directory_entry
1729{
1730 typedef _VSTD_FS::path _Path;
1731
1732public:
1733 // constructors and destructors
1734 directory_entry() _NOEXCEPT = default;
1735 directory_entry(directory_entry const&) = default;
1736 directory_entry(directory_entry&&) _NOEXCEPT = default;
1737
1738 _LIBCPP_INLINE_VISIBILITY
1739 explicit directory_entry(_Path const& __p) : __p_(__p) {}
1740
1741 ~directory_entry() {}
1742
1743 directory_entry& operator=(directory_entry const&) = default;
1744 directory_entry& operator=(directory_entry&&) _NOEXCEPT = default;
1745
1746 _LIBCPP_INLINE_VISIBILITY
1747 void assign(_Path const& __p) {
1748 __p_ = __p;
1749 }
1750
1751 _LIBCPP_INLINE_VISIBILITY
1752 void replace_filename(_Path const& __p) {
1753 __p_ = __p_.parent_path() / __p;
1754 }
1755
1756 _LIBCPP_INLINE_VISIBILITY
1757 _Path const& path() const _NOEXCEPT {
1758 return __p_;
1759 }
1760
1761 _LIBCPP_INLINE_VISIBILITY
1762 operator const _Path&() const _NOEXCEPT {
1763 return __p_;
1764 }
1765
1766 _LIBCPP_INLINE_VISIBILITY
1767 file_status status() const {
1768 return _VSTD_FS::status(__p_);
1769 }
1770
1771 _LIBCPP_INLINE_VISIBILITY
1772 file_status status(error_code& __ec) const _NOEXCEPT {
1773 return _VSTD_FS::status(__p_, __ec);
1774 }
1775
1776 _LIBCPP_INLINE_VISIBILITY
1777 file_status symlink_status() const {
1778 return _VSTD_FS::symlink_status(__p_);
1779 }
1780
1781 _LIBCPP_INLINE_VISIBILITY
1782 file_status symlink_status(error_code& __ec) const _NOEXCEPT {
1783 return _VSTD_FS::symlink_status(__p_, __ec);
1784 }
1785
1786 _LIBCPP_INLINE_VISIBILITY
1787 bool operator< (directory_entry const& __rhs) const _NOEXCEPT {
1788 return __p_ < __rhs.__p_;
1789 }
1790
1791 _LIBCPP_INLINE_VISIBILITY
1792 bool operator==(directory_entry const& __rhs) const _NOEXCEPT {
1793 return __p_ == __rhs.__p_;
1794 }
1795
1796 _LIBCPP_INLINE_VISIBILITY
1797 bool operator!=(directory_entry const& __rhs) const _NOEXCEPT {
1798 return __p_ != __rhs.__p_;
1799 }
1800
1801 _LIBCPP_INLINE_VISIBILITY
1802 bool operator<=(directory_entry const& __rhs) const _NOEXCEPT {
1803 return __p_ <= __rhs.__p_;
1804 }
1805
1806 _LIBCPP_INLINE_VISIBILITY
1807 bool operator> (directory_entry const& __rhs) const _NOEXCEPT {
1808 return __p_ > __rhs.__p_;
1809 }
1810
1811 _LIBCPP_INLINE_VISIBILITY
1812 bool operator>=(directory_entry const& __rhs) const _NOEXCEPT {
1813 return __p_ >= __rhs.__p_;
1814 }
1815private:
1816 _Path __p_;
1817};
1818
1819
1820class directory_iterator;
1821class recursive_directory_iterator;
1822class __dir_stream;
1823
1824class __dir_element_proxy {
1825public:
1826
1827 inline _LIBCPP_INLINE_VISIBILITY
1828 directory_entry operator*() { return _VSTD::move(__elem_); }
1829
1830private:
1831 friend class directory_iterator;
1832 friend class recursive_directory_iterator;
1833 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
1834 __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {}
1835 directory_entry __elem_;
1836};
1837
1838class directory_iterator
1839{
1840public:
1841 typedef directory_entry value_type;
1842 typedef ptrdiff_t difference_type;
1843 typedef value_type const* pointer;
1844 typedef value_type const& reference;
1845 typedef input_iterator_tag iterator_category;
1846
1847public:
1848 //ctor & dtor
1849 directory_iterator() _NOEXCEPT
1850 { }
1851
1852 explicit directory_iterator(const path& __p)
1853 : directory_iterator(__p, nullptr)
1854 { }
1855
1856 directory_iterator(const path& __p, directory_options __opts)
1857 : directory_iterator(__p, nullptr, __opts)
1858 { }
1859
1860 directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT
1861 : directory_iterator(__p, &__ec)
1862 { }
1863
1864 directory_iterator(const path& __p, directory_options __opts,
1865 error_code& __ec) _NOEXCEPT
1866 : directory_iterator(__p, &__ec, __opts)
1867 { }
1868
1869 directory_iterator(const directory_iterator&) = default;
1870 directory_iterator(directory_iterator&&) = default;
1871 directory_iterator& operator=(const directory_iterator&) = default;
1872
1873 directory_iterator& operator=(directory_iterator&& __o) _NOEXCEPT {
1874 // non-default implementation provided to support self-move assign.
1875 if (this != &__o) {
1876 __imp_ = _VSTD::move(__o.__imp_);
1877 }
1878 return *this;
1879 }
1880
1881 ~directory_iterator() = default;
1882
1883 const directory_entry& operator*() const {
1884 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
1885 return __deref();
1886 }
1887
1888 const directory_entry* operator->() const
1889 { return &**this; }
1890
1891 directory_iterator& operator++()
1892 { return __increment(); }
1893
1894 __dir_element_proxy operator++(int) {
1895 __dir_element_proxy __p(**this);
1896 __increment();
1897 return __p;
1898 }
1899
1900 directory_iterator& increment(error_code& __ec) _NOEXCEPT
1901 { return __increment(&__ec); }
1902
1903private:
1904 friend bool operator==(const directory_iterator& __lhs,
1905 const directory_iterator& __rhs) _NOEXCEPT;
1906
1907 // construct the dir_stream
1908 _LIBCPP_FUNC_VIS
1909 directory_iterator(const path&, error_code *, directory_options = directory_options::none);
1910 _LIBCPP_FUNC_VIS
1911 directory_iterator& __increment(error_code * __ec = nullptr);
1912 _LIBCPP_FUNC_VIS
1913 const directory_entry& __deref() const;
1914
1915private:
1916 shared_ptr<__dir_stream> __imp_;
1917};
1918
1919
1920inline _LIBCPP_INLINE_VISIBILITY
1921bool operator==(const directory_iterator& __lhs,
1922 const directory_iterator& __rhs) _NOEXCEPT {
1923 return __lhs.__imp_ == __rhs.__imp_;
1924}
1925
1926inline _LIBCPP_INLINE_VISIBILITY
1927bool operator!=(const directory_iterator& __lhs,
1928 const directory_iterator& __rhs) _NOEXCEPT {
1929 return !(__lhs == __rhs);
1930}
1931
1932// enable directory_iterator range-based for statements
1933inline _LIBCPP_INLINE_VISIBILITY
1934directory_iterator begin(directory_iterator __iter) _NOEXCEPT {
1935 return __iter;
1936}
1937
1938inline _LIBCPP_INLINE_VISIBILITY
1939directory_iterator end(const directory_iterator&) _NOEXCEPT {
1940 return directory_iterator();
1941}
1942
1943class recursive_directory_iterator {
1944public:
1945 using value_type = directory_entry;
1946 using difference_type = std::ptrdiff_t;
1947 using pointer = directory_entry const *;
1948 using reference = directory_entry const &;
1949 using iterator_category = std::input_iterator_tag;
1950
1951public:
1952 // constructors and destructor
1953 _LIBCPP_INLINE_VISIBILITY
1954 recursive_directory_iterator() _NOEXCEPT
1955 : __rec_(false)
1956 {}
1957
1958 _LIBCPP_INLINE_VISIBILITY
1959 explicit recursive_directory_iterator(const path& __p,
1960 directory_options __xoptions = directory_options::none)
1961 : recursive_directory_iterator(__p, __xoptions, nullptr)
1962 { }
1963
1964 _LIBCPP_INLINE_VISIBILITY
1965 recursive_directory_iterator(const path& __p,
1966 directory_options __xoptions, error_code& __ec) _NOEXCEPT
1967 : recursive_directory_iterator(__p, __xoptions, &__ec)
1968 { }
1969
1970 _LIBCPP_INLINE_VISIBILITY
1971 recursive_directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT
1972 : recursive_directory_iterator(__p, directory_options::none, &__ec)
1973 { }
1974
1975 recursive_directory_iterator(const recursive_directory_iterator&) = default;
1976 recursive_directory_iterator(recursive_directory_iterator&&) = default;
1977
1978 recursive_directory_iterator &
1979 operator=(const recursive_directory_iterator&) = default;
1980
1981 _LIBCPP_INLINE_VISIBILITY
1982 recursive_directory_iterator &
1983 operator=(recursive_directory_iterator&& __o) noexcept {
1984 // non-default implementation provided to support self-move assign.
1985 if (this != &__o) {
1986 __imp_ = _VSTD::move(__o.__imp_);
1987 __rec_ = __o.__rec_;
1988 }
1989 return *this;
1990 }
1991
1992 ~recursive_directory_iterator() = default;
1993
1994 _LIBCPP_INLINE_VISIBILITY
1995 const directory_entry& operator*() const
1996 { return __deref(); }
1997
1998 _LIBCPP_INLINE_VISIBILITY
1999 const directory_entry* operator->() const
2000 { return &__deref(); }
2001
2002 recursive_directory_iterator& operator++()
2003 { return __increment(); }
2004
2005 _LIBCPP_INLINE_VISIBILITY
2006 __dir_element_proxy operator++(int) {
2007 __dir_element_proxy __p(**this);
2008 __increment();
2009 return __p;
2010 }
2011
2012 _LIBCPP_INLINE_VISIBILITY
2013 recursive_directory_iterator& increment(error_code& __ec) _NOEXCEPT
2014 { return __increment(&__ec); }
2015
2016 _LIBCPP_FUNC_VIS directory_options options() const;
2017 _LIBCPP_FUNC_VIS int depth() const;
2018
2019 _LIBCPP_INLINE_VISIBILITY
2020 void pop() { __pop(); }
2021
2022 _LIBCPP_INLINE_VISIBILITY
2023 void pop(error_code& __ec)
2024 { __pop(&__ec); }
2025
2026 _LIBCPP_INLINE_VISIBILITY
2027 bool recursion_pending() const
2028 { return __rec_; }
2029
2030 _LIBCPP_INLINE_VISIBILITY
2031 void disable_recursion_pending()
2032 { __rec_ = false; }
2033
2034private:
2035 recursive_directory_iterator(const path& __p, directory_options __opt,
2036 error_code *__ec);
2037
2038 _LIBCPP_FUNC_VIS
2039 const directory_entry& __deref() const;
2040
2041 _LIBCPP_FUNC_VIS
2042 bool __try_recursion(error_code* __ec);
2043
2044 _LIBCPP_FUNC_VIS
2045 void __advance(error_code* __ec=nullptr);
2046
2047 _LIBCPP_FUNC_VIS
2048 recursive_directory_iterator& __increment(error_code *__ec=nullptr);
2049
2050 _LIBCPP_FUNC_VIS
2051 void __pop(error_code* __ec=nullptr);
2052
2053 friend bool operator==(const recursive_directory_iterator&,
2054 const recursive_directory_iterator&) _NOEXCEPT;
2055
2056 struct __shared_imp;
2057 shared_ptr<__shared_imp> __imp_;
2058 bool __rec_;
2059}; // class recursive_directory_iterator
2060
2061
2062_LIBCPP_INLINE_VISIBILITY
2063inline bool operator==(const recursive_directory_iterator& __lhs,
2064 const recursive_directory_iterator& __rhs) _NOEXCEPT
2065{
2066 return __lhs.__imp_ == __rhs.__imp_;
2067}
2068
2069_LIBCPP_INLINE_VISIBILITY
2070inline bool operator!=(const recursive_directory_iterator& __lhs,
2071 const recursive_directory_iterator& __rhs) _NOEXCEPT
2072{
2073 return !(__lhs == __rhs);
2074}
2075// enable recursive_directory_iterator range-based for statements
2076inline _LIBCPP_INLINE_VISIBILITY
2077recursive_directory_iterator begin(recursive_directory_iterator __iter) _NOEXCEPT {
2078 return __iter;
2079}
2080
2081inline _LIBCPP_INLINE_VISIBILITY
2082recursive_directory_iterator end(const recursive_directory_iterator&) _NOEXCEPT {
2083 return recursive_directory_iterator();
2084}
2085
2086_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
2087
2088#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM