30 #ifndef _GLIBCXX_FS_PATH_H 31 #define _GLIBCXX_FS_PATH_H 1 33 #if __cplusplus >= 201703L 36 #include <type_traits> 42 #include <system_error> 46 #include <bits/shared_ptr.h> 49 #if defined(_WIN32) && !defined(__CYGWIN__) 50 # define _GLIBCXX_FILESYSTEM_IS_WINDOWS 1 54 namespace std _GLIBCXX_VISIBILITY(default)
56 _GLIBCXX_BEGIN_NAMESPACE_VERSION
60 _GLIBCXX_BEGIN_NAMESPACE_CXX11
70 template<
typename _CharT,
typename _Ch = remove_const_t<_CharT>>
71 using __is_encoded_char
72 = __or_<is_same<_Ch, char>,
73 #ifdef _GLIBCXX_USE_CHAR8_T 74 is_same<_Ch, char8_t>,
76 is_same<_Ch, wchar_t>,
77 is_same<_Ch, char16_t>,
78 is_same<_Ch, char32_t>>;
80 template<
typename _Iter,
81 typename _Iter_traits = std::iterator_traits<_Iter>>
82 using __is_path_iter_src
83 = __and_<__is_encoded_char<typename _Iter_traits::value_type>,
85 typename _Iter_traits::iterator_category>>;
87 template<
typename _Iter>
88 static __is_path_iter_src<_Iter>
89 __is_path_src(_Iter,
int);
91 template<
typename _CharT,
typename _Traits,
typename _Alloc>
92 static __is_encoded_char<_CharT>
93 __is_path_src(
const basic_string<_CharT, _Traits, _Alloc>&,
int);
95 template<
typename _CharT,
typename _Traits>
96 static __is_encoded_char<_CharT>
97 __is_path_src(
const basic_string_view<_CharT, _Traits>&,
int);
99 template<
typename _Unknown>
101 __is_path_src(
const _Unknown&, ...);
103 template<
typename _Tp1,
typename _Tp2>
104 struct __constructible_from;
106 template<
typename _Iter>
107 struct __constructible_from<_Iter, _Iter>
108 : __is_path_iter_src<_Iter>
111 template<
typename _Source>
112 struct __constructible_from<_Source, void>
113 : decltype(__is_path_src(std::declval<_Source>(), 0))
116 template<
typename _Tp1,
typename _Tp2 =
void>
117 using _Path =
typename 119 __not_<is_void<remove_pointer_t<_Tp1>>>,
120 __constructible_from<_Tp1, _Tp2>>::value,
123 template<
typename _Source>
125 _S_range_begin(_Source __begin) {
return __begin; }
127 struct __null_terminated { };
129 template<
typename _Source>
130 static __null_terminated
131 _S_range_end(_Source) {
return {}; }
133 template<
typename _CharT,
typename _Traits,
typename _Alloc>
135 _S_range_begin(
const basic_string<_CharT, _Traits, _Alloc>& __str)
136 {
return __str.data(); }
138 template<
typename _CharT,
typename _Traits,
typename _Alloc>
140 _S_range_end(
const basic_string<_CharT, _Traits, _Alloc>& __str)
141 {
return __str.data() + __str.size(); }
143 template<
typename _CharT,
typename _Traits>
145 _S_range_begin(
const basic_string_view<_CharT, _Traits>& __str)
146 {
return __str.data(); }
148 template<
typename _CharT,
typename _Traits>
150 _S_range_end(
const basic_string_view<_CharT, _Traits>& __str)
151 {
return __str.data() + __str.size(); }
153 template<
typename _Tp,
154 typename _Iter = decltype(_S_range_begin(std::declval<_Tp>())),
155 typename _Val =
typename std::iterator_traits<_Iter>::value_type>
156 using __value_type_is_char
160 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 161 typedef wchar_t value_type;
162 static constexpr value_type preferred_separator = L
'\\';
164 typedef char value_type;
165 static constexpr value_type preferred_separator =
'/';
169 enum format :
unsigned char { native_format, generic_format, auto_format };
175 path(
const path& __p) =
default;
178 #if _GLIBCXX_USE_CXX11_ABI || _GLIBCXX_FULLY_DYNAMIC_STRING == 0 181 : _M_pathname(std::move(__p._M_pathname)),
182 _M_cmpts(std::move(__p._M_cmpts))
185 path(string_type&& __source, format = auto_format)
186 : _M_pathname(
std::move(__source))
187 { _M_split_cmpts(); }
189 template<
typename _Source,
190 typename _Require = _Path<_Source>>
191 path(_Source
const& __source, format = auto_format)
192 : _M_pathname(_S_convert(_S_range_begin(__source),
193 _S_range_end(__source)))
194 { _M_split_cmpts(); }
196 template<
typename _InputIterator,
197 typename _Require = _Path<_InputIterator, _InputIterator>>
198 path(_InputIterator __first, _InputIterator __last, format = auto_format)
199 : _M_pathname(_S_convert(__first, __last))
200 { _M_split_cmpts(); }
202 template<
typename _Source,
203 typename _Require = _Path<_Source>,
204 typename _Require2 = __value_type_is_char<_Source>>
205 path(_Source
const& __source,
const locale& __loc, format = auto_format)
206 : _M_pathname(_S_convert_loc(_S_range_begin(__source),
207 _S_range_end(__source), __loc))
208 { _M_split_cmpts(); }
210 template<
typename _InputIterator,
211 typename _Require = _Path<_InputIterator, _InputIterator>,
212 typename _Require2 = __value_type_is_char<_InputIterator>>
213 path(_InputIterator __first, _InputIterator __last,
const locale& __loc,
214 format = auto_format)
215 : _M_pathname(_S_convert_loc(__first, __last, __loc))
216 { _M_split_cmpts(); }
222 path& operator=(
const path&);
223 path& operator=(path&&) noexcept;
224 path& operator=(string_type&& __source);
225 path& assign(string_type&& __source);
227 template<typename _Source>
229 operator=(_Source const& __source)
230 {
return *
this = path(__source); }
232 template<
typename _Source>
234 assign(_Source
const& __source)
235 {
return *
this = path(__source); }
237 template<
typename _InputIterator>
238 _Path<_InputIterator, _InputIterator>&
239 assign(_InputIterator __first, _InputIterator __last)
240 {
return *
this = path(__first, __last); }
244 path& operator/=(
const path& __p);
246 template <
class _Source>
248 operator/=(_Source
const& __source)
250 _M_append(_S_convert(_S_range_begin(__source), _S_range_end(__source)));
254 template<
typename _Source>
256 append(_Source
const& __source)
258 _M_append(_S_convert(_S_range_begin(__source), _S_range_end(__source)));
262 template<
typename _InputIterator>
263 _Path<_InputIterator, _InputIterator>&
264 append(_InputIterator __first, _InputIterator __last)
266 _M_append(_S_convert(__first, __last));
272 path& operator+=(
const path& __x);
273 path& operator+=(
const string_type& __x);
274 path& operator+=(
const value_type* __x);
275 path& operator+=(value_type __x);
276 path& operator+=(basic_string_view<value_type> __x);
278 template<
typename _Source>
280 operator+=(_Source
const& __x) {
return concat(__x); }
282 template<
typename _CharT>
283 _Path<_CharT*, _CharT*>&
284 operator+=(_CharT __x);
286 template<
typename _Source>
288 concat(_Source
const& __x)
290 _M_concat(_S_convert(_S_range_begin(__x), _S_range_end(__x)));
294 template<
typename _InputIterator>
295 _Path<_InputIterator, _InputIterator>&
296 concat(_InputIterator __first, _InputIterator __last)
298 _M_concat(_S_convert(__first, __last));
304 void clear() noexcept { _M_pathname.clear(); _M_split_cmpts(); }
306 path& make_preferred();
307 path& remove_filename();
308 path& replace_filename(
const path& __replacement);
309 path& replace_extension(
const path& __replacement = path());
311 void swap(path& __rhs) noexcept;
315 const string_type& native() const noexcept {
return _M_pathname; }
316 const value_type* c_str() const noexcept {
return _M_pathname.c_str(); }
317 operator string_type()
const {
return _M_pathname; }
319 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
320 typename _Allocator = std::allocator<_CharT>>
322 string(
const _Allocator& __a = _Allocator())
const;
325 #if _GLIBCXX_USE_WCHAR_T 328 #ifdef _GLIBCXX_USE_CHAR8_T 329 __attribute__((__abi_tag__(
"__u8")))
330 std::u8string u8string() const;
333 #endif // _GLIBCXX_USE_CHAR8_T 338 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
339 typename _Allocator = std::allocator<_CharT>>
341 generic_string(
const _Allocator& __a = _Allocator())
const;
344 #if _GLIBCXX_USE_WCHAR_T 347 #ifdef _GLIBCXX_USE_CHAR8_T 348 __attribute__((__abi_tag__(
"__u8")))
349 std::u8string generic_u8string() const;
352 #endif // _GLIBCXX_USE_CHAR8_T 358 int compare(
const path& __p)
const noexcept;
359 int compare(
const string_type& __s)
const noexcept;
360 int compare(
const value_type* __s)
const noexcept;
361 int compare(basic_string_view<value_type> __s)
const noexcept;
365 path root_name()
const;
366 path root_directory()
const;
367 path root_path()
const;
368 path relative_path()
const;
369 path parent_path()
const;
370 path filename()
const;
372 path extension()
const;
376 [[nodiscard]]
bool empty() const noexcept {
return _M_pathname.empty(); }
377 bool has_root_name() const noexcept;
378 bool has_root_directory() const noexcept;
379 bool has_root_path() const noexcept;
380 bool has_relative_path() const noexcept;
381 bool has_parent_path() const noexcept;
382 bool has_filename() const noexcept;
383 bool has_stem() const noexcept;
384 bool has_extension() const noexcept;
385 bool is_absolute() const noexcept;
386 bool is_relative() const noexcept {
return !is_absolute(); }
389 path lexically_normal()
const;
390 path lexically_relative(
const path& base)
const;
391 path lexically_proximate(
const path& base)
const;
395 typedef iterator const_iterator;
397 iterator
begin()
const;
398 iterator
end()
const;
401 template<
typename _CharT,
typename _Traits>
403 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
const path& __p)
405 __os <<
std::quoted(__p.string<_CharT, _Traits>());
410 template<
typename _CharT,
typename _Traits>
416 __p = std::move(__tmp);
423 friend bool operator<(
const path& __lhs,
const path& __rhs) noexcept
424 {
return __lhs.compare(__rhs) < 0; }
427 friend bool operator<=(
const path& __lhs,
const path& __rhs) noexcept
428 {
return !(__rhs < __lhs); }
431 friend bool operator>(
const path& __lhs,
const path& __rhs) noexcept
432 {
return __rhs < __lhs; }
435 friend bool operator>=(
const path& __lhs,
const path& __rhs) noexcept
436 {
return !(__lhs < __rhs); }
439 friend bool operator==(
const path& __lhs,
const path& __rhs) noexcept
440 {
return __lhs.compare(__rhs) == 0; }
443 friend bool operator!=(
const path& __lhs,
const path& __rhs) noexcept
444 {
return !(__lhs == __rhs); }
447 friend path
operator/(
const path& __lhs,
const path& __rhs)
449 path __result(__lhs);
455 template<
typename _InputIterator,
456 typename _Traits = std::iterator_traits<_InputIterator>,
460 _S_string_from_iter(_InputIterator __source)
463 for (_CharT __ch = *__source; __ch != _CharT(); __ch = *++__source)
469 enum class _Type : unsigned char {
470 _Multi = 0, _Root_name, _Root_dir, _Filename
473 path(basic_string_view<value_type> __str, _Type __type)
476 __glibcxx_assert(__type != _Type::_Multi);
477 _M_cmpts.type(__type);
480 enum class _Split { _Stem, _Extension };
482 void _M_append(basic_string_view<value_type>);
483 void _M_concat(basic_string_view<value_type>);
485 pair<const string_type*, size_t> _M_find_extension() const noexcept;
487 template<typename _CharT>
490 static basic_string_view<value_type>
491 _S_convert(value_type* __src, __null_terminated)
494 static basic_string_view<value_type>
495 _S_convert(
const value_type* __src, __null_terminated)
498 static basic_string_view<value_type>
499 _S_convert(value_type* __first, value_type* __last)
500 {
return {__first, __last - __first}; }
502 static basic_string_view<value_type>
503 _S_convert(
const value_type* __first,
const value_type* __last)
504 {
return {__first, __last - __first}; }
506 template<
typename _Iter>
508 _S_convert(_Iter __first, _Iter __last)
510 using __value_type =
typename std::iterator_traits<_Iter>::value_type;
511 return _Cvt<typename remove_cv<__value_type>::type>::
512 _S_convert(__first, __last);
515 template<
typename _InputIterator>
517 _S_convert(_InputIterator __src, __null_terminated)
520 auto __s = _S_string_from_iter(__src);
522 return string_type(_S_convert(__s.data(), __s.data() + __s.size()));
526 _S_convert_loc(
const char* __first,
const char* __last,
529 template<
typename _Iter>
531 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
534 return _S_convert_loc(__str.data(), __str.data()+__str.size(), __loc);
537 template<
typename _InputIterator>
539 _S_convert_loc(_InputIterator __src, __null_terminated,
542 const std::string __s = _S_string_from_iter(__src);
543 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
546 template<
typename _CharT,
typename _Traits,
typename _Allocator>
547 static basic_string<_CharT, _Traits, _Allocator>
548 _S_str_convert(
const string_type&,
const _Allocator& __a);
550 void _M_split_cmpts();
552 _Type _M_type() const noexcept {
return _M_cmpts.type(); }
554 string_type _M_pathname;
560 using value_type = _Cmpt;
561 using iterator = value_type*;
562 using const_iterator =
const value_type*;
566 _List(_List&&) =
default;
567 _List& operator=(
const _List&);
568 _List& operator=(_List&&) =
default;
571 _Type type() const noexcept
572 {
return _Type{
reinterpret_cast<uintptr_t
>(_M_impl.get()) & 0x3}; }
574 void type(_Type) noexcept;
576 int size() const noexcept;
577 bool empty() const noexcept;
579 void swap(_List& __l) noexcept { _M_impl.swap(__l._M_impl); }
580 int capacity() const noexcept;
581 void reserve(
int,
bool);
588 const_iterator
begin() const;
589 const_iterator
end() const;
591 value_type& front() noexcept;
592 value_type& back() noexcept;
593 const value_type& front() const noexcept;
594 const value_type& back() const noexcept;
597 void _M_erase_from(const_iterator __pos);
602 void operator()(_Impl*)
const noexcept;
604 unique_ptr<_Impl, _Impl_deleter> _M_impl;
611 inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
619 filesystem_error(
const string& __what_arg, error_code __ec);
621 filesystem_error(
const string& __what_arg,
const path& __p1,
624 filesystem_error(
const string& __what_arg,
const path& __p1,
625 const path& __p2, error_code __ec);
627 filesystem_error(
const filesystem_error&) =
default;
628 filesystem_error& operator=(
const filesystem_error&) =
default;
635 const path& path1() const noexcept;
636 const path& path2() const noexcept;
637 const
char* what() const noexcept;
641 std::__shared_ptr<const _Impl> _M_impl;
645 template<typename _InputIterator>
647 u8path(_InputIterator __first, _InputIterator __last)
648 -> decltype(filesystem::path(__first, __last,
std::locale::classic()))
650 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 652 std::codecvt_utf8_utf16<path::value_type> __cvt;
653 path::string_type __tmp;
654 if constexpr (is_pointer_v<_InputIterator>)
656 if (__str_codecvt_in_all(__first, __last, __tmp, __cvt))
657 return path{ __tmp };
662 const char*
const __ptr = __u8str.
data();
663 if (__str_codecvt_in_all(__ptr, __ptr + __u8str.size(), __tmp, __cvt))
664 return path{ __tmp };
666 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
667 "Cannot convert character sequence",
668 std::make_error_code(errc::illegal_byte_sequence)));
671 return path{ __first, __last };
676 template<
typename _Source>
678 u8path(
const _Source& __source)
681 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 682 if constexpr (is_convertible_v<const _Source&, std::string_view>)
684 const std::string_view __s = __source;
685 return filesystem::u8path(__s.data(), __s.data() + __s.size());
689 std::string __s = path::_S_string_from_iter(__source);
690 return filesystem::u8path(__s.data(), __s.data() + __s.size());
693 return path{ __source };
697 struct path::_Cmpt : path
699 _Cmpt(basic_string_view<value_type> __s, _Type __t,
size_t __pos)
700 : path(__s, __t), _M_pos(__pos) { }
702 _Cmpt() : _M_pos(-1) { }
709 struct path::_Cvt<path::value_type>
711 template<
typename _Iter>
713 _S_convert(_Iter __first, _Iter __last)
714 {
return string_type{__first, __last}; }
717 #if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T 720 struct path::_Cvt<char8_t>
722 template<
typename _Iter>
724 _S_convert(_Iter __first, _Iter __last)
725 {
return string_type(__first, __last); }
729 template<
typename _CharT>
733 _S_convert(
const _CharT* __f,
const _CharT* __l)
735 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 737 if constexpr (is_same_v<_CharT, char>)
739 struct _UCvt :
std::codecvt<wchar_t, char, std::mbstate_t>
741 if (__str_codecvt_in_all(__f, __l, __wstr, __cvt))
744 #ifdef _GLIBCXX_USE_CHAR8_T 745 else if constexpr (is_same_v<_CharT, char8_t>)
747 const char* __f2 = (
const char*)__f;
748 const char* __l2 = (
const char*)__l;
749 std::codecvt_utf8_utf16<wchar_t> __wcvt;
750 if (__str_codecvt_in_all(__f2, __l2, __wstr, __wcvt))
756 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t>
759 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
761 const char* __f2 = __str.
data();
762 const char* __l2 = __f2 + __str.size();
763 std::codecvt_utf8_utf16<wchar_t> __wcvt;
764 if (__str_codecvt_in_all(__f2, __l2, __wstr, __wcvt))
769 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t>
772 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
775 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
776 "Cannot convert character sequence",
777 std::make_error_code(errc::illegal_byte_sequence)));
781 _S_convert(_CharT* __f, _CharT* __l)
783 return _S_convert(const_cast<const _CharT*>(__f),
784 const_cast<const _CharT*>(__l));
787 template<
typename _Iter>
789 _S_convert(_Iter __first, _Iter __last)
792 return _S_convert(__str.data(), __str.data() + __str.size());
795 template<
typename _Iter,
typename _Cont>
797 _S_convert(__gnu_cxx::__normal_iterator<_Iter, _Cont> __first,
798 __gnu_cxx::__normal_iterator<_Iter, _Cont> __last)
799 {
return _S_convert(__first.base(), __last.base()); }
806 using difference_type = std::ptrdiff_t;
807 using value_type = path;
808 using reference =
const path&;
809 using pointer =
const path*;
812 iterator() : _M_path(nullptr), _M_cur(), _M_at_end() { }
814 iterator(
const iterator&) =
default;
815 iterator& operator=(
const iterator&) =
default;
820 iterator& operator++();
821 iterator operator++(
int) {
auto __tmp = *
this; ++*
this;
return __tmp; }
823 iterator& operator--();
824 iterator operator--(
int) {
auto __tmp = *
this; --*
this;
return __tmp; }
826 friend bool operator==(
const iterator& __lhs,
const iterator& __rhs)
827 {
return __lhs._M_equals(__rhs); }
829 friend bool operator!=(
const iterator& __lhs,
const iterator& __rhs)
830 {
return !__lhs._M_equals(__rhs); }
835 bool _M_is_multi()
const {
return _M_path->_M_type() == _Type::_Multi; }
837 friend difference_type
838 __path_iter_distance(
const iterator& __first,
const iterator& __last)
840 __glibcxx_assert(__first._M_path !=
nullptr);
841 __glibcxx_assert(__first._M_path == __last._M_path);
842 if (__first._M_is_multi())
844 else if (__first._M_at_end == __last._M_at_end)
847 return __first._M_at_end ? -1 : 1;
851 __path_iter_advance(iterator& __i, difference_type __n)
859 __glibcxx_assert(__i._M_path !=
nullptr);
860 __glibcxx_assert(__i._M_is_multi());
866 iterator(
const path* __path, path::_List::const_iterator __iter)
867 : _M_path(__path), _M_cur(__iter), _M_at_end()
870 iterator(
const path* __path,
bool __at_end)
871 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
874 bool _M_equals(iterator)
const;
877 path::_List::const_iterator _M_cur;
883 path::operator=(path&& __p) noexcept
885 if (&__p ==
this) [[__unlikely__]]
888 _M_pathname = std::move(__p._M_pathname);
889 _M_cmpts = std::move(__p._M_cmpts);
895 path::operator=(string_type&& __source)
896 {
return *
this = path(std::move(__source)); }
899 path::assign(string_type&& __source)
900 {
return *
this = path(std::move(__source)); }
903 path::operator+=(
const string_type& __x)
910 path::operator+=(
const value_type* __x)
917 path::operator+=(value_type __x)
919 _M_concat(basic_string_view<value_type>(&__x, 1));
924 path::operator+=(basic_string_view<value_type> __x)
930 template<
typename _CharT>
931 inline path::_Path<_CharT*, _CharT*>&
932 path::operator+=(_CharT __x)
935 return concat(__addr, __addr + 1);
939 path::make_preferred()
941 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 942 std::replace(_M_pathname.begin(), _M_pathname.end(), L
'/',
943 preferred_separator);
948 inline void path::swap(path& __rhs) noexcept
950 _M_pathname.swap(__rhs._M_pathname);
951 _M_cmpts.swap(__rhs._M_cmpts);
954 template<
typename _CharT,
typename _Traits,
typename _Allocator>
956 path::_S_str_convert(
const string_type& __str,
const _Allocator& __a)
958 static_assert(!is_same_v<_CharT, value_type>);
960 using _WString = basic_string<_CharT, _Traits, _Allocator>;
962 if (__str.size() == 0)
963 return _WString(__a);
965 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 968 std::codecvt_utf8_utf16<value_type> __cvt;
970 using _CharAlloc = __alloc_rebind<_Allocator, char>;
971 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
972 _String __u8str{_CharAlloc{__a}};
973 const value_type* __wfirst = __str.data();
974 const value_type* __wlast = __wfirst + __str.size();
975 if (__str_codecvt_out_all(__wfirst, __wlast, __u8str, __cvt)) {
976 if constexpr (is_same_v<_CharT, char>)
980 const char* __first = __u8str.data();
981 const char* __last = __first + __u8str.size();
983 const value_type* __first = __str.data();
984 const value_type* __last = __first + __str.size();
988 #ifdef _GLIBCXX_USE_CHAR8_T 989 if constexpr (is_same_v<_CharT, char8_t>)
990 return _WString(__first, __last, __a);
995 _WString __wstr(__a);
996 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t> { } __cvt;
997 if (__str_codecvt_in_all(__first, __last, __wstr, __cvt))
1001 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 1004 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
1005 "Cannot convert character sequence",
1006 std::make_error_code(errc::illegal_byte_sequence)));
1009 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1010 inline basic_string<_CharT, _Traits, _Allocator>
1013 if constexpr (is_same_v<_CharT, value_type>)
1014 return { _M_pathname.
c_str(), _M_pathname.length(), __a };
1016 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
1022 #if _GLIBCXX_USE_WCHAR_T 1027 #ifdef _GLIBCXX_USE_CHAR8_T 1028 inline std::u8string
1029 path::u8string()
const {
return string<char8_t>(); }
1032 path::u8string()
const 1034 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 1037 std::codecvt_utf8_utf16<value_type> __cvt;
1038 const value_type* __first = _M_pathname.data();
1039 const value_type* __last = __first + _M_pathname.size();
1040 if (__str_codecvt_out_all(__first, __last, __str, __cvt))
1042 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
1043 "Cannot convert character sequence",
1044 std::make_error_code(errc::illegal_byte_sequence)));
1049 #endif // _GLIBCXX_USE_CHAR8_T 1057 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1059 path::generic_string(
const _Allocator& __a)
const 1061 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 1062 const value_type __slash = L
'/';
1064 const value_type __slash =
'/';
1066 string_type __str(__a);
1068 if (_M_type() == _Type::_Root_dir)
1069 __str.assign(1, __slash);
1072 __str.reserve(_M_pathname.size());
1073 bool __add_slash =
false;
1074 for (
auto& __elem : *
this)
1078 __str += __elem._M_pathname;
1079 __add_slash = __elem._M_type() == _Type::_Filename;
1083 if constexpr (is_same_v<_CharT, value_type>)
1086 return _S_str_convert<_CharT, _Traits>(__str, __a);
1090 path::generic_string()
const 1091 {
return generic_string<char>(); }
1093 #if _GLIBCXX_USE_WCHAR_T 1095 path::generic_wstring()
const 1096 {
return generic_string<wchar_t>(); }
1099 #ifdef _GLIBCXX_USE_CHAR8_T 1100 inline std::u8string
1101 path::generic_u8string()
const 1102 {
return generic_string<char8_t>(); }
1105 path::generic_u8string()
const 1106 {
return generic_string(); }
1110 path::generic_u16string()
const 1111 {
return generic_string<char16_t>(); }
1114 path::generic_u32string()
const 1115 {
return generic_string<char32_t>(); }
1118 path::compare(
const string_type& __s)
const noexcept
1119 {
return compare(basic_string_view<value_type>(__s)); }
1122 path::compare(
const value_type* __s)
const noexcept
1123 {
return compare(basic_string_view<value_type>(__s)); }
1126 path::filename()
const 1130 else if (_M_type() == _Type::_Filename)
1132 else if (_M_type() == _Type::_Multi)
1134 if (_M_pathname.back() == preferred_separator)
1136 auto& __last = *--
end();
1137 if (__last._M_type() == _Type::_Filename)
1146 auto ext = _M_find_extension();
1147 if (ext.first && ext.second != 0)
1148 return path{ext.first->substr(0, ext.second)};
1153 path::extension()
const 1155 auto ext = _M_find_extension();
1156 if (ext.first && ext.second != string_type::npos)
1157 return path{ext.first->substr(ext.second)};
1162 path::has_stem() const noexcept
1164 auto ext = _M_find_extension();
1165 return ext.first && ext.second != 0;
1169 path::has_extension() const noexcept
1171 auto ext = _M_find_extension();
1172 return ext.first && ext.second != string_type::npos;
1176 path::is_absolute() const noexcept
1178 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 1179 return has_root_name() && has_root_directory();
1181 return has_root_directory();
1185 inline path::iterator
1188 if (_M_type() == _Type::_Multi)
1189 return iterator(
this, _M_cmpts.begin());
1190 return iterator(
this, empty());
1193 inline path::iterator
1196 if (_M_type() == _Type::_Multi)
1197 return iterator(
this, _M_cmpts.end());
1198 return iterator(
this,
true);
1201 inline path::iterator&
1202 path::iterator::operator++()
1204 __glibcxx_assert(_M_path !=
nullptr);
1205 if (_M_path->_M_type() == _Type::_Multi)
1207 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1212 __glibcxx_assert(!_M_at_end);
1218 inline path::iterator&
1219 path::iterator::operator--()
1221 __glibcxx_assert(_M_path !=
nullptr);
1222 if (_M_path->_M_type() == _Type::_Multi)
1224 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1229 __glibcxx_assert(_M_at_end);
1235 inline path::iterator::reference
1236 path::iterator::operator*()
const 1238 __glibcxx_assert(_M_path !=
nullptr);
1239 if (_M_path->_M_type() == _Type::_Multi)
1241 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1248 path::iterator::_M_equals(iterator __rhs)
const 1250 if (_M_path != __rhs._M_path)
1252 if (_M_path ==
nullptr)
1254 if (_M_path->_M_type() == path::_Type::_Multi)
1255 return _M_cur == __rhs._M_cur;
1256 return _M_at_end == __rhs._M_at_end;
1260 _GLIBCXX_END_NAMESPACE_CXX11
1264 distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
1265 {
return __path_iter_distance(__first, __last); }
1267 template<
typename _InputIterator,
typename _Distance>
1269 advance(filesystem::path::iterator& __i, _Distance __n)
1270 { __path_iter_advance(__i, static_cast<ptrdiff_t>(__n)); }
1272 extern template class __shared_ptr<const filesystem::filesystem_error::_Impl>;
1274 _GLIBCXX_END_NAMESPACE_VERSION
1279 #endif // _GLIBCXX_FS_PATH_H constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
_GLIBCXX20_CONSTEXPR complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
auto quoted(const _CharT *__string, _CharT __delim=_CharT('"'), _CharT __escape = _CharT('\))
Manipulator for quoted strings.
basic_string< char16_t > u16string
A string of char16_t.
Container class for localization functionality.The locale class is first a class wrapper for C librar...
ISO C++ entities toplevel namespace is std.
_GLIBCXX_END_NAMESPACE_CXX11 typedef basic_string< char > string
A string of char.
Primary class template codecvt.NB: Generic, mostly useless implementation.
const _CharT * data() const noexcept
Return const pointer to contents.
Template class basic_ostream.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
typename remove_cv< _Tp >::type remove_cv_t
Alias template for remove_cv.
void push_back(_CharT __c)
Append a single character.
Template class basic_istream.
Thrown to indicate error code of underlying system.
static const locale & classic()
Return reference to the C locale.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
void replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__old_value, const _Tp &__new_value)
Replace each occurrence of one value in a sequence with another value.
_GLIBCXX20_CONSTEXPR complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
basic_string< wchar_t > wstring
A string of wchar_t.
size_t hash_value(const path &__p) noexcept
Compare paths.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
path u8path(_InputIterator __first, _InputIterator __last)
Create a path from a UTF-8-encoded sequence of char.
Bidirectional iterators support a superset of forward iterator operations.
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
basic_string< char32_t > u32string
A string of char32_t.
Define a member typedef type only if a boolean constant is true.