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